1

We are working on project. Every colleague have different folder for the install In my case the folder of my files is in

C:\\p4_3202\\CAR\\car.rt.appl\\dev\\car.components\\cars\\res\\car.rt.components.cars\\resources\\js;

for other colleague it could be in

C:\\my_3202\\CAR2\\car.rt.appl\\dev\\car.components\\cars\\res\\car.rt.components.cars\\resources\\js;

it is depends how you config your perforce.

I need to read files from my folder but i don't know the name of the folder ( as i explained it could be different )

 File folderFile = new File(folder); 

How i can find the location of my folder ? ( c:\p4\......test.js ) I tried with

 System.getProperty("sun.java.command"); System.getProperty("user.home") 

but it didn't give me the path of my folder

6
  • 3
    What do you mean by "my folder"? Commented Dec 31, 2012 at 11:01
  • the folder that the files of the java are located in the eclipse Commented Dec 31, 2012 at 11:04
  • in my case C:\p4_3202\CARS\cars.rt.appl\dev\new_car\ Commented Dec 31, 2012 at 11:05
  • Either refer to it as a full path, or by a relative path. Commented Dec 31, 2012 at 11:05
  • I don't have the name of the folder I want to find it Commented Dec 31, 2012 at 11:15

4 Answers 4

1

I would use a system property for each user. So all users tell where perforce is installed (might already exist a property for this, look at the docs). This could then be read by your code like:

 System.getenv().get("PROP"); 

On a unix/Linux system you can set the property in a shell/environment variable using:

 export PROP=thepath 

Windows was a long time ago for me but if I remember correctly its somewhere under System on control panel :)

Update: http://www.itechtalk.com/thread3595.html

Sign up to request clarification or add additional context in comments.

7 Comments

When i did it String str = System.getProperty("PROP"); I got null as result
Did you export (or set) the property before? Otherwise null is to be expected ;)
I didn't set before when I need to set the Property
Did you read my answer? You need to set the property as a system property before accessing it. How to do this is os dependent, looking at your examples I'd guess your on windows. Updated answer with a link.
I did it but I still don't get any value.
|
0

file.getAbsolutePath() or file.getAbsoluteFile()

4 Comments

so I need to create empty File object ?
I don't want to inserted the path of the file as default
I believe he is looking for a way to find a file and read it. Using your solution, he will have access to the file he is currently reading.
The issue that the folder could be different folder in different people depends how they install the project
0
String path = new java.io.File(".").getCanonicalPath(); 

Comments

0

If it are files for reading only, being stored inside the final produced jar, then use URL url = getClass().getResource("/.../...") or InputStream in = getClass().getResourceAsStream("/.../...").

That uses a path inside the jar/class path. Using only the jar would never do with File.

1 Comment

what I will do with the result It is not possible to create File with URL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.