问题描述
importjava.io.BufferedReader;importjava.io.File;importjava.io.FileReader;importjava.util.Vector;publicclassFileOperate{Stringstring;Filef=newFile(".\price.txt");String[]price;Stringstr="";publicStringreadFile(){try{if(!f.exists()){f.createNewFile();}else{FileReaderfr=newFileReader(".\price.txt");BufferedReaderbr=newBufferedReader(fr);while((string=br.readLine())!=null){string+=str;}}System.out.println(string);}catch(Exceptione){System.out.println("safasdf");e.printStackTrace();}returnstring;}publicvoidwriteFile(){//FileWriterfw=newFileWriter(f);}publicstaticvoidmain(String[]args){newFileOperate().readFile();}}
解决方案
解决方案二:
importjava.io.BufferedReader;importjava.io.File;importjava.io.FileReader;importjava.util.Vector;publicclassFileOperate{Stringstring="";Filef=newFile("./price.txt");String[]price;Stringstr="";publicStringreadFile(){try{if(!f.exists()){f.createNewFile();}else{FileReaderfr=newFileReader("./price.txt");BufferedReaderbr=newBufferedReader(fr);while((str=br.readLine())!=null){string+=str+"n";}}System.out.println(string);}catch(Exceptione){System.out.println("safasdf");e.printStackTrace();}returnstring;}publicvoidwriteFile(){//FileWriterfw=newFileWriter(f);}publicstaticvoidmain(String[]args){newFileOperate().readFile();}}
解决方案三:
文件路径写错了“.\price.txt”应该修改下
解决方案四:
肯定是取不到路径。