package shurushuchu;
import java.io.*;
public class test5 {
public static void main(String[] args) {
try {
File file = new File("d:/IoDemo.java");
if(!file.exists())
{
file.createNewFile();
}
//输出的内容
FileOutputStream fos = new FileOutputStream(file);
String str ="你好我是张三";
//把数据源转成byte[]数组
byte [] b = str.getBytes();
//写入数据
fos.write(b);
//关闭流自动释放文件
fos.close();
System.out.println("写入文件完成");
//字节输入流
FileInputStream fis = new FileInputStream(file);
//装载读入的数组
byte [] d = new byte[12];
//全部内容的字符串
int i = fis.read(d);
String str1 = new String(d);
System.out.println("读入的内容"+str1);
//关闭文件
fis.close();
//创建新文件
File file1 = new File("d:/iodemo.txt,");
if(!file1.exists())
{
file1.createNewFile();
}
FileWriter sos = new FileWriter(file1);
sos.write(str1);
sos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}