Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does java look for files?

Tags:

java

file

I'm trying to read a file in java:

Public class Test{

public static void main (String [] args) throws IOException {

BufferedReader f = new BufferedReader(new FileReader("test.in"));

//...

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));

//...                                 

}

}

1) Where should the location of "test.in" be? (src? bin? ???)

2) Where will "test.out" be located?

like image 483
Anonymous181 Avatar asked May 17 '12 21:05

Anonymous181


2 Answers

A relative path'ed file is looked for in the directory specified by System.getProperty("user.dir")

like image 79
MeBigFatGuy Avatar answered Sep 28 '22 02:09

MeBigFatGuy


The answer is the working folder, which means the folder in which you executed the "java ..." command. This is the project folder in eclipse projects for instance.

like image 20
Hakan Serce Avatar answered Sep 28 '22 00:09

Hakan Serce