try {
FileOutputStream output = new FileOutputStream(file);
byte[] b = new byte[10];
for (int i = 0; i < b.length; ++i)
b[i] = (byte) i;
output.write(b);
output.close();
FileInputStream input = new FileInputStream(file);
List<Byte> c = new ArrayList<Byte>();
int len = 0;
while ((len = input.read()) != -1) {
Byte by = Byte.valueOf((byte) len);
c.add(by);
}
for (Byte d : c)
System.out.println(d);
input.close();
} catch (IOException e) {
e.printStackTrace();
}
2.bufferedinputstream and bufferedoutputstream
try {
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file));
String str = "I can make it";
char[] c = new char[20];
c = str.toCharArray();
for (char ch : c)
output.write(ch);
output.close();
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
List<Character> L = new ArrayList<Character>();
int len = 0;
while ((len = input.read()) != -1) {
Character C = Character.valueOf((char) len);
L.add(C);
}
for (Character d : L)
System.out.println(d);
System.err.println(L.size());
input.close();
} catch (FileNotFoundException e) {
System.err.println("file out found");
e.printStackTrace();
} catch (IOException e) {
System.err.println("写入文件异常");
e.printStackTrace();
}
1.fileinputsteam and fileoutputstreamtry { FileOutputStream output = new FileOutputStream(file); byte[] b = new byte[10]; for (int i = 0; i < b.length; ++i) b[i] = (byte) i; outpu...