IO流FileOutputStream(文件字节输出流)和FileInputStream(文件字节输入流)
import java.io.*;
public class FileByteinputAndoutput {
public static void main(String[] args) {
File f = new File("D:/word.txt");
FileOutputStream out = null;
try {
out = new FileOutputStream(f,false);
String str = "你见过洛杉矶,凌晨四点的样子吗?";
byte b[] = str.getBytes();
out.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
FileInputStream in = null;
try {
in = new FileInputStream(f);
byte b1[] = new byte[1024];
int len;
while((len = in.read(b1)) != -1) {
System.out.println("文件中的数据是:" + new String(b1,0,len));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}