I've probably spent way too long on this question, but:
C:\temp>notepad test_in.txt =>
Hello Java input!
In the same directory, create "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";
}
Finally, run it - specify the full package name:
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
'Hope that helps explain a few things, including:
Your "default directory" with respect to compiling and running
How "packages" relate to "directories"
The fact that Java will put your class files in the package directory (not necessarily your working directory)