蹭点分^_^public static void main(String[] args) throws Exception{

解决方案 »

  1.   

    用个大try包整个main里的代码包起来,这样上面异常都捕获。
      

  2.   

    else
    {
    System.out.println("No Existing");
                                return;
    }
    如果文件不存在,就返回好了。
      

  3.   

    import java.io.*;public class FileReaderTest {
    public static void main(String[] args) {
    String fn = "D://1.txt";
    try {
    File f = new File("D://", "1.txt");
    if (f.exists()) {
    System.out.println("Existing");
    } else {
    System.out.println("No Existing");
    } FileReader fr = new FileReader(f); //这里出错
    } catch (IOException e) {
    ;
    }
    }
    }
      

  4.   

    这个问题也要讨论半天,java就是这样,“FileReader fr = new FileReader(f);  ”这个类new的时候规定了可能抛这个异常,因此,你必须使用try,catch,而不管你那个文件实际存在不存在。
      

  5.   

    FileReader fr = new FileReader(f);
    首先上面这一行要捕捉异常,象下面这样,
    try
    {
       FileReader fr = new FileReader(f);
    }
    catch(FileNotFoundException e)
    {
    }
    然后你的路径写错了,是斜杠,而不是反斜杠
      

  6.   

    谢谢大家!
    今天看了原代码才知道要捕捉异常!在看代码时看到一段奇怪的代码(可能是我太菜!)
    在新问题中提出,请大家继续帮帮帮忙!
    new 谢谢(N)!
    网址:http://community.csdn.net/Expert/topic/3361/3361374.xml?temp=.333645