还是这样
D:\javacode>javac ReadFromFile.java
ReadFromFile.java:12: ')' expected
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:17: illegal start of expression
File dir = new File(stfDir.toString());
^
ReadFromFile.java:23: ')' expected
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:28: illegal start of expression
File readFrom = new File(dir,stfFilename.toString());
^
ReadFromFile.java:12: incompatible types
found : char
required: boolean
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:23: incompatible types
found : char
required: boolean
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable readFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable reafFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable reafFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:35: cannot resolve symbol
symbol : variable readFrom
location: class ReadFromFile
new RandomAccessFile(readFrom,"rw");
^
ReadFromFile.java:38: cannot resolve symbol
symbol : variable file
location: class ReadFromFile
System.out.println(file.readLine());
^
11 errors
D:\javacode>javac ReadFromFile.java
ReadFromFile.java:12: ')' expected
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:17: illegal start of expression
File dir = new File(stfDir.toString());
^
ReadFromFile.java:23: ')' expected
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:28: illegal start of expression
File readFrom = new File(dir,stfFilename.toString());
^
ReadFromFile.java:12: incompatible types
found : char
required: boolean
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:23: incompatible types
found : char
required: boolean
while((char ch = (char)System.in.read())!='\n')
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable readFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable reafFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:31: cannot resolve symbol
symbol : variable reafFrom
location: class ReadFromFile
if(readFrom.isFile() && reafFrom.canWrite() && reafFrom.canRead(
))
^
ReadFromFile.java:35: cannot resolve symbol
symbol : variable readFrom
location: class ReadFromFile
new RandomAccessFile(readFrom,"rw");
^
ReadFromFile.java:38: cannot resolve symbol
symbol : variable file
location: class ReadFromFile
System.out.println(file.readLine());
^
11 errors
解决方案 »
- 有很多相同的按钮怎么判断单击哪个
- poi 設置execl自動調整列寬
- 想让hibernate配置的c3p0报错,它死活就是不报错,谁有办法让它报错?
- 内容分页的问题
- 有关Class对象中Class.forName("package.classname")的疑惑?
- 如何将字符串加密成Base64和MD5那样的字符串,但要可逆
- 在windows2003下装j2ee sdk诊断不通过
- 各位帮我看一下ODBC数据源的问题
- applet如何弹一个message框,让用户确认?
- 请问那里有tomcat下载
- 页面之间的链接用全名链接(URL),会出现数据丢失吗?Session会变吗?在线等待!
- 一个初学者关于jdbc数据库的连接问题!(急)
while((ch = System.in.read())!='\n')
{
stfFilename.appendChar((char)ch);
}
而非(char)System.in.read
我觉得是这儿出了问题。
一回事了。只是这儿你的char强制转换的似乎是System
改为:
char ch;
while((ch = (char)System.in.read())!='\n')
就ok了!我调试过的!
public class ReadFromFile {
String ch;
public ReadFromFile() { }
public static void main(String[] args) {
try{
System.out.println("Please enter a directory that the file located in:");
//构造待读取文件的目录
StringBuffer stfDir = new StringBuffer();
//从键盘获取输入字符,存储进入字符缓冲区
char ch = (char)System.in.read();
while(ch!='\n')
{
stfDir.append(ch);
}
//创建目录文件对象
File dir = new File(stfDir.toString());
System.out.println("Please enter a filename that want to read:");
//获取待读取的文件名
StringBuffer stfFilename = new StringBuffer();
//从键盘获取输入字符,存储进入字符缓冲区
while(ch !='\n')
{
stfFilename.append(ch);
}
//创建文件对象
File readFrom = new File(dir,stfFilename.toString());
//判断文件是否为目录、是否具有写权限、读权限
if(readFrom.isFile() && readFrom.canWrite() && readFrom.canRead())
{
//创建RandomAccessFile对象
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!");
} catch(IOException ex)
{
System.err.println(ex.getMessage() );
}
}}这样就好了!god bless you!