package Test2016;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Filewrite {
public static void main(String[] args) {
//read();//读取文件;
write();//写入文件;
}


public static void read() {
int b = 0;
FileReader r = null;
// 测试一个读的程序;
try {
r = new FileReader(
"E:\\MyEclipse 10\\JAVA\\src\\Test2016\\StudentSystem.java");
} catch (FileNotFoundException e) {
System.out.println("文件找不到");
System.exit(-1);
}
try {
while ((b = r.read()) != -1) {
System.out.print((char) b);
}
r.close();
} catch (IOException e1) {
System.out.println("读取失败");
System.exit(-1);
}

}
public static void write(){
int b=0;
FileWriter w=null;
try{
w=new FileWriter("D:\\test\\test.txt");
for(int i=0;i<1000;i++){
w.write(i);
}
w.close();
System.out.println("文件写入成功");
}catch(IOException e1){
System.out.println("文件写入失败");
}
}
}