写一个简单的写入和读取
读取
package contorller;
import java.io.FileOutputStream;
import java.io.IOException;
public class ZIj {
public static void main(String []args) throws IOException {
FileOutputStream f=new FileOutputStream("d:/w.txt",true);
f.write(1);
f.write(2);
f.flush();
}
}
结果
1
2
写入
package contorller;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class RZIJ {
public static void main(String[]args) throws IOException {
FileInputStream f=new FileInputStream("d:/w.txt");
int b=f.read();
int c=f.read();
System.out.println(b);
System.out.println(c);
}
}
这上面只是我的简单写法,利用字节数组是一样的意思