还是这样
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

解决方案 »

  1.   

    method readFrom() does not exist
      

  2.   

    tryint ch;
    while((ch = System.in.read())!='\n')
    {
     stfFilename.appendChar((char)ch);
    }
      

  3.   

    (char)(System.in.read())
    而非(char)System.in.read
    我觉得是这儿出了问题。
      

  4.   

    当然能不能一个String对象cast到一个char对象,那又是另外
    一回事了。只是这儿你的char强制转换的似乎是System
      

  5.   

    While((char ch = (char)System.in.read())!='\n')
    改为:
    char ch;
    while((ch = (char)System.in.read())!='\n')
    就ok了!我调试过的!
      

  6.   

    import java.io.*;
    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!