import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MyFileInOutputStream {
public static void main(String[] args) {
writeTofile();
readFromFile();
}
private static void readFromFile() {
byte buffer[] = new byte[512];
int num = 0;
try {
FileInputStream in = new FileInputStream("D:\\ex\\a\\a.txt");
num = in.read(buffer);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<num;i++){
System.out.println(buffer[i]+" ");
}
}
private static void writeTofile() {
try {
//FileOutputStream out=new FileOutputStream("d:/ex/a/b.dat");//覆盖
FileOutputStream out=new FileOutputStream("d:/ex/a/b.dat",true);//追加
byte[] buffer={13,10,97,98,99,100,101,102,49,55};
out.write(buffer);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}