String inputStream file转化
String --> InputStream
ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
InputStream --> String
String inputStream2String(InputStream is){
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null){
buffer.append(line);
}
return buffer.toString();
}
File --> InputStream
InputStream in = new FileInputStream(file);
InputStream --> File
public void inputstreamtofile(InputStream ins,File file){
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
}
String--> InputSource
InputSource is=new InputSource(new StringReader(xmlStr))
String inputStream file转化的更多相关文章
- Java中InputStream和String之间的转化
https://blog.csdn.net/lmy86263/article/details/60479350 在Java中InputStream和String之间的转化十分普遍,本文主要是总结一下转 ...
- Java InputStream、String、File相互转化
String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...
- Java InputStream、String、File相互转化 --- good
String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...
- 30天C#基础巩固------面向鸭子编程,关于string和File的练习
面向对象编程就是面向抽象的父类进行编程,具体的实现不用考虑,由子类决定.<经典的说法--面向鸭子编程> eg:鸭子的编程,<对于多态的理解> 我们都习惯把使用 ...
- Timestame类型和String 类型的转化
Timestame类型和String 类型的转化 String转化为Timestamp: SimpleDateFormat df = new SimpleDateFormat("yyyy-M ...
- java常用string inputStream转换
1.String –> InputStream InputStrem is = new ByteArrayInputStream(str.getBytes()); 或者 ByteArrayInp ...
- Junit 注解 类加载器 .动态代理 jdbc 连接池 DButils 事务 Arraylist Linklist hashset 异常 哈希表的数据结构,存储过程 Map Object String Stringbufere File类 文件过滤器_原理分析 flush方法和close方法 序列号冲突问题
Junit 注解 3).其它注意事项: 1).@Test运行的方法,不能有形参: 2).@Test运行的方法,不能有返回值: 3).@Test运行的方法,不能是静态方法: 4).在一个类中,可以同时定 ...
- C# byte[]数组和string的互相转化 (四种方法)
C# byte[]数组和string的互相转化 (四种方法) 第一种 [csharp] view plain copy string str = System.Text.Encoding.UTF8.G ...
- CString/string 区别及其转化
CString/string 区别及其转化 利用MFC进行编程时,我们从对话框中利用GetWindowText得到的字符串是CString类型,CString是属于MFC的类.而一些标准C/C++库函 ...
随机推荐
- 为laravel分页样式制定class
做的项目有一个上翻页和下翻页,使用了框架提供的
- 安装Laravel遇到You must enable the openssl extension to download files via https问题
刚看了一篇文章说了2014年最火的10个php框架,看到了Laravel,于是便自己试试,孰料刚安装便遇到了一个问题(由于一不小心关掉了cmd,此处无法截图显示),便是如文章标题中所说的那样,goog ...
- selenium python 环境搭建
说真的关于这个网上有太多的文章了,不想在这上面浪费过多的精神,简单说一下: 1.下载python(我的2.7) 2.下载python的基础工具包(setuptools) 3.下载python的安装包管 ...
- C#文件操作系列(一)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Flask的部署
当前对部署flask的一些学习: 1.全局安装nginx 1.1 nginx的配置文件怎么写? $ sudo rm /etc/nginx/sites-enabled/default $ sudo to ...
- maven管理多模块系统
1.创建mydemo项目cd d:\myworkmvn archetype:create -DgroupId=com.example.mydemo -DartifactId=mydemo 生成myde ...
- C#中,为什么结构体也可以设置构造函数?
结构体派生自ValueType,ValueType派生自Object,可访问Object的方法.结构体是一种缩小版的类.结构体不能继承.结构体总是有一个无参数的默认构造函数,不允许替换.结构体可指定字 ...
- iOS开发:获取设备IP地址
一.导入头文件 //首先导入头文件信息 #include <ifaddrs.h> #include <arpa/inet.h> #include <net/if.h> ...
- Extjs之success、failure
Ext.form.Action.Submit的配置选项success.failure是根据返回json中success属性判断的,如果success为true,则success,false则failu ...
- oracle--insert
常规insert语法就不说了,还有些特殊用法 1. insert all into table1(col1,col2) values(v1,v2) into table2(col1,col2) va ...