我可能在这个问题上花了太长时间,但是:
C:\temp>notepad test_in.txt =>
你好Java输入!
在同一目录中,创建“Test.java”:
package com.mytest;
import java.io.*;
public class Test {
public static void main (String [] args) throws IOException {
System.out.println ("Current directory is " + new File(".").getAbsolutePath());
System.out.println ("Reading file " + INPUT_FILE + "...");
BufferedReader fis =
new BufferedReader(new FileReader(INPUT_FILE));
String s = fis.readLine ();
fis.close ();
System.out.println ("Contents: " + s + ".");
System.out.println ("Writing file " + INPUT_FILE + "...");
PrintWriter fos =
new PrintWriter(new BufferedWriter(new FileWriter("test_out.txt")));
fos.println ("Hello Java output");
fos.close ();
System.out.println ("Done.");
}
private static final String INPUT_FILE = "test_in.txt";
private static final String OUTPUT_FILE = "test_out.txt";
}
最后,运行它——指定完整的包名:
C:\temp>javac -d . Test.java
C:\temp>dir com\mytest
Volume in drive C has no label.
Volume Serial Number is 7096-6FDD
Directory of C:\temp\com\mytest
05/17/2012 02:23 PM <DIR> .
05/17/2012 02:23 PM <DIR> ..
05/17/2012 02:29 PM 1,375 Test.class
1 File(s) 1,375 bytes
2 Dir(s) 396,478,521,344 bytes free
C:\temp>java com.mytest.Test
Current directory is C:\temp\.
Reading file test_in.txt...
Contents: Hello Java input!.
Writing file test_in.txt...
Done.
C:\temp>dir/od test*.txt
Volume in drive C has no label.
Volume Serial Number is 7096-6FDD
Directory of C:\temp
05/17/2012 02:24 PM 17 test_in.txt
05/17/2012 02:29 PM 19 test_out.txt
2 File(s) 36 bytes
'希望这有助于解释一些事情,包括: