当前位置: 代码迷 >> Java相关 >> 紧急求助
  详细解决方案

紧急求助

热度:438   发布时间:2004-08-03 09:43:00.0
紧急求助

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')


----------------解决方案--------------------------------------------------------
请说明一下你编写此程序的意图好吗?你的编码风格实在很差,看了我受不了。是不是想要输入随机文件所在文件夹和文件名而后读取是吗?
----------------解决方案--------------------------------------------------------
谢谢
是的,就是要输入随机文件所在文件夹和文件名而后读取。好的编程风格是不是都要加上注释?
----------------解决方案--------------------------------------------------------
  相关解决方案