虚心请教是什么原因导致的错误
工程中分别建立读写文件的类
public class ReadFile{
public static String read()
{
try{
File read = new File( "c:\\djym.txt ");
BufferedReader br = new BufferedReader(new FileReader(read));
String temp = null;
temp = br.readLine();
br.close();
return temp;
}
catch(
FileNotFoundException e){ //文件未找到
System.out.println (e);
return null;
}
catch(
IOException e){
System.out.println (e);
return null;
}
}
}
public class WriteFile{
public static void write(String str){
try{
File write = new File( "c:\\djym.txt ");
BufferedWriter bw = new BufferedWriter(
new FileWriter(write));
while(str != null){
//写文件
bw.write(str); //只适用Windows系统
}
bw.close();
return;
}
catch(File
NotFoundException e)
{ //文件未找到
System.out.println (e);
return;
}
catch(IOException e)
{
System.out.println (e);
return;
}
}
}
------解决方案--------------------在你的main函数中,你获得的temp值应该是10001,
然后你使用WriteFile.write();
现在来看看write()代码.
while(str != null){
//写文件
bw.write(str); //只适用Windows系统
}
死循环,一直往文件中写入 "10001 "