Relative paths in Java IO relate to the current working directory. In Eclipse, this is usually the root of the project. You also write outinstead outFile. Here the younger rewrite:
File file = new File("member.txt");
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.write("test");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) try { writer.close(); } catch (IOException ignore) {}
}
System.out.printf("File is located at %s%n", file.getAbsolutePath());
Closing is mandatory because it flushes the recorded data to a file and releases the file lock.
, Java IO. , classpath. ClassLoader#getResource(), getResourceAsStream() ..