Results 1 to 13 of 13
Thread: File Path
- 08-03-2011, 08:27 PM #1
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
File Path
FileWriter fstream = new FileWriter("abc.txt");
The above code creates the file in the folder, where Eclipse is installed. However, I want to create the file in the bin folder of the Java project.
Or
What is the way to get the path of bin folder of the Java project, in Java?
Please guide.
regards,
- 08-03-2011, 10:24 PM #2
You could use the JFileChooser class to allow the user to find the folder.What is the way to get the path of bin folder of the Java project, in Java?
- 08-04-2011, 01:26 AM #3
I just tried it because I didn't believe you.FileWriter fstream = new FileWriter("abc.txt");
The above code creates the file in the folder, where Eclipse is installed.
It creates the file in your project-folder (under the Eclipse-folder).
The bin is normally just under the project folder, so "bin\\abc.txt" will do the trick.
(I guess I would prefer not to use the bin-directory, but a resource (or whatever) folder on the same level.
The bin is often cleared (erased) by Eclipse, and files from src are copied there, apart from class-files of course).No bug ever had to calculate its fitnessfunction.
- 08-04-2011, 09:51 AM #4
- 08-04-2011, 01:19 PM #5
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
I am using mac version of Eclipse (64 bit), may be this is one of the reason. On my computer, the file is stored at the below address
/Users/usera/ECLIPSES/eclipse-classic-64/Eclipse.app/Contents/MacOS
Jodokus advised "I guess I would prefer not to use the bin-directory, but a resource (or whatever) folder on the same level"
yes, Thanks for advice. But still I do not know, how to get the path of that directory, or how to store newly created file in project folder.
Norm advised "You could use the JFileChooser class to allow the user to find the folder."
but I want to be bit more simple, so that user do not do any thing regarding file Path.
Actually, I want to distribute a Java project(code) to some of my colleagues. Presently I have hard-coded the path in code. One can understand that this is not the right way.
Please advise.
- 08-04-2011, 01:23 PM #6
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
Please note, I run my project as an Eclipse Application (not a simple Java application)
regards,
- 08-04-2011, 01:26 PM #7
I want to distribute a Java project(code)What is the difference between an Eclipse app and a simple Java app?my project as an Eclipse Application(not a simple Java application)
- 08-04-2011, 01:44 PM #8
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
I mean, I run my project as an Eclipse application and this opens a new child "Eclipse Window". Whereas in a regular Java application, may be new child "Eclipse window" is not necessary. I guess this is the reason that it creates file at path
/Users/usera/ECLIPSES/eclipse-classic-64/Eclipse.app/Contents/MacOS
note the "Eclipse.app" in path.
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String folder= workspace.getRoot().getLocation().toFile().getPath ().toString();
I used above code, it provides some absolute path but still, not the one, I am looking for i.e the address of the project folder
regards,
- 08-04-2011, 01:47 PM #9
What is its value for a simple Java app? Which I assume is completely inside of a jar file.the address of the project folder
- 08-04-2011, 01:57 PM #10
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
my apology, I could not understand your recent reply, however as an explanation of my problem, please find below code
public static void main(String[] args) throws IOException {
FileWriter fstream = new FileWriter("zxy.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("This is test\n");
out.close();
}
I run above code and it stores the file at correct (wanted )path
/Users/usera/Documents/workspace/Test
However, when I run the actual project as an "Eclipse application", it creates file at unwanted path.
regards,
- 08-04-2011, 02:00 PM #11
I run above code and it stores the file at correct (wanted )pathIf the first one does what you want, do it that way.I run the actual project as an "Eclipse application", it creates file at unwanted path.
- 08-04-2011, 02:11 PM #12
Member
- Join Date
- May 2010
- Posts
- 30
- Rep Power
- 0
It creates file at wanted path when project is run as "Java Application". However, it creates file at unwanted path, when it runs as "Eclipse Application". Please note, I am supposed to run my project as an Eclipse Application, as the developed project is an Eclipse plugin.
I created a test project to check the behavior of FileWriter. I learned that Java runtime creates file in the project folder (as you think), if the project run as "Java Application", however, the behavior of Java runtime is different, if we run project as "Eclipse application".
Anyhow, thanks for your advice.
regards,
regards,
- 08-04-2011, 03:25 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
It's not the behaviour of the runtime that's different.
It's the "home" directory of the app that is.
Your plugin is run inside Eclipse as part of Eclipse, and it's "home" is in that directory inside Eclipse.
When run as its own project its "home" is the project.
Not much you can do about that.
What (exactly) are you trying to get?
A path to an open project?
Any open project?
Similar Threads
-
file path
By billq in forum New To JavaReplies: 2Last Post: 04-11-2010, 05:47 PM -
ant with a jar file in path to run
By javastuden in forum Advanced JavaReplies: 0Last Post: 02-22-2010, 05:59 AM -
file path
By ras_pari in forum Advanced JavaReplies: 2Last Post: 10-12-2009, 11:25 AM -
find file with * on the path
By itaipee in forum New To JavaReplies: 7Last Post: 07-08-2009, 08:05 AM -
file path
By Arsench in forum New To JavaReplies: 7Last Post: 10-30-2008, 05:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks