如何在Java中创建新文件?

我是一个初学者,因此将不胜感激! 我不断收到代码中的错误

Exception in thread "main" java.io.FileNotFoundException: test.in (The system cannot find the file specified).
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at test.Tips.main(Tips.java:17)

该代码应该从文件“ test.in”中的单个输入行读取一对小整数,并将它们的总和打印到文件“ test.out”中。

我的代码是:

    package test;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.StringTokenizer;

    class Tips {


   public static void main (String [] args) throws IOException {
        // Use BufferedReader rather than RandomAccessFile; it's much faster
        BufferedReader f = new BufferedReader(new FileReader("test.in"));
        // input file name goes above
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));
        // Use StringTokenizer vs. readLine/split -- lots faster
        StringTokenizer st = new StringTokenizer(f.readLine());
          // Get line, break into tokens
        int i1 = Integer.parseInt(st.nextToken());    // first integer
        int i2 = Integer.parseInt(st.nextToken());    // second integer
        out.println(i1+i2);                           // output result
        out.close();                                  // close the output file
   }
 }

我认为解决此错误的唯一方法是创建一个名为test.in的文件,但我不知道如何。我正在使用Eclipse BTW。

评论