I\O字节流,使用FileOutputStream写入文件
package com.ioflow.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamDemo {
public static void main(String[] args) {
File file = new File("test/test.txt");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
String str="鬼知道我要干什么!";
byte [] bytes=str.getBytes();
for (int i = 0; i < bytes.length; i++) {
fos.write(bytes[i]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}