import java.io.*; class ReadFromFile { public static void main(String args[]) { System.out.println("Please enter a directory that th file located in:"); StringBuffer stfDir = new StringBuffer(); while((char ch=(char)System.in.read())!='\n') { stfDir.appendChar(ch); } File dir=new File(stfDir.toString()); System.out.println("Please enter a filename that want to read:"); StringBuffer stfFilename = new StringBuffer(); while((char ch=(char)System.in.read())!='\n') { stfFilename.appendChar(ch); } File readFrom = new File(dir,stfFilename.toString()); if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead()) { RandomAccessFile rafFile = new RandomAccessFile(readFrom,"rw"); while((rafFile.getFilePointer())<(rafFile.length())) System.out.println(rafFile.readLine()); rafFile.close(); } else System.out.println("File cann't be read!"); }
}
各位老大,编译后出现一下错误,不知道怎么回事,帮帮我,谢谢!!
ReadFromFile.java:8: ')' expected while((char ch=(char)System.in.read())!='\n') ^ ReadFromFile.java:12: illegal start of expression File dir=new File(stfDir.toString()); ^ ReadFromFile.java:15: ')' expected while((char ch=(char)System.in.read())!='\n') ^ ReadFromFile.java:19: illegal start of expression File readFrom = new File(dir,stfFilename.toString()); ^ ReadFromFile.java:8: incompatible types found : char required: boolean ReadFromFile.java:12: illegal start of expression File dir=new File(stfDir.toString()); ^ ReadFromFile.java:15: ')' expected while((char ch=(char)System.in.read())!='\n') ^ ReadFromFile.java:19: illegal start of expression File readFrom = new File(dir,stfFilename.toString()); ^ ReadFromFile.java:8: incompatible types found : char required: boolean while((char ch=(char)System.in.read())!='\n') ^ ReadFromFile.java:15: incompatible types found : char required: boolean while((char ch=(char)System.in.read())!='\n') ^ ReadFromFile.java:20: cannot resolve symbol symbol : variable readFrom location: class ReadFromFile if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead()) ^ ReadFromFile.java:20: cannot resolve symbol symbol : variable readFrom location: class ReadFromFile if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead()) ^ ReadFromFile.java:20: cannot resolve symbol symbol : variable readFrom location: class ReadFromFile if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead()) ^ ReadFromFile.java:22: cannot resolve symbol symbol : variable readFrom location: class ReadFromFile RandomAccessFile rafFile = new RandomAccessFile(readFrom ,"rw"); ^ while((char ch=(char)System.in.read())!='\n')