| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1167 人关注过本帖
标题:紧急求助
只看楼主 加入收藏
mazhaohu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-8-3
收藏
 问题点数:0 回复次数:2 
紧急求助

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

搜索更多相关主题的帖子: public import file 
2004-08-03 09:43
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
请说明一下你编写此程序的意图好吗?你的编码风格实在很差,看了我受不了。是不是想要输入随机文件所在文件夹和文件名而后读取是吗?

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2004-08-03 12:46
mazhaohu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-8-3
收藏
得分:0 
谢谢
是的,就是要输入随机文件所在文件夹和文件名而后读取。好的编程风格是不是都要加上注释?
2004-08-03 13:42
快速回复:紧急求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053957 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved