抛出FileNotFoundException不起作用

时间:2016-04-04 15:30:53

标签: java filenotfoundexception throws

import java.io.*;
import java.util.*;

public class Exercise3_2
{
   public static void main(String[] args) throws FileNotFoundException
   {
   String firstName;
   String lastName;

   double score1, score2, score3, score4, score5;
   double avg;

   Scanner inFile = new Scanner(new FileReader("test.txt"));

   PrintWriter outFile = new PrintWriter ("testavg.out");

   firstName = inFile.next();
   lastName = inFile.next();

   outFile.println("Student name : " + firstName + " " + lastName);

   score1 = inFile.nextDouble();
   score2 = inFile.nextDouble();
   score3 = inFile.nextDouble();
   score4 = inFile.nextDouble();

   outFile.println("Test scores: " + score1 + " ," + score2 + " ," + score3
                                   + " ," + score4);

   avg = (score1 + score2 + score3 + score4) / 4;

   outFile.printf("Average test scores: %5.2f %n, avg");

   inFile.close();
   outFile.close();

   }
}                         

每当我运行这个,这就是我得到的: 线程" main"中的例外情况java.io.FileNotFoundException:test.txt(系统找不到指定的文件)

...... WHY !!!!

0 个答案:

没有答案