473,382 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Get current directory and set current directory.

dmjpro
2,476 2GB
How do I get current directory in JAVA?
And how do I set Current Directory in JAVA?

When JVM runs a class file then what is it's current directory?
Is it the JVM running path???

Please help!

Debasis Jana.
Mar 14 '08 #1
8 10990
sukatoa
539 512MB
How do I get current directory in JAVA?
And how do I set Current Directory in JAVA?

When JVM runs a class file then what is it's current directory?
Is it the JVM running path???

Please help!

Debasis Jana.
I have little doubt about your question...

Would it mean that you like to know the current directory of your program/file?

If this is what you mean,

Just create a file(tempfile maybe) and get its AbsolutePath()....

Since the returned string represents the file you have created (with its dir.)...
Just remove that filename... ( the last )....

If this is not what you mean,

Update us...
Sukatoa
Mar 14 '08 #2
JosAH
11,448 Expert 8TB
I have little doubt about your question...

Would it mean that you like to know the current directory of your program/file?

If this is what you mean,

Just create a file(tempfile maybe) and get its AbsolutePath()....

Since the returned string represents the file you have created (with its dir.)...
Just remove that filename... ( the last )....

If this is not what you mean,

Update us...
Sukatoa
You don't even have to create a real file for that; an abstract pathname is enough:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
You do have to handle potential IOExceptions.

kind regards,

Jos
Mar 14 '08 #3
sukatoa
539 512MB
You don't even have to create a real file for that; an abstract pathname is enough:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
You do have to handle potential IOExceptions.

kind regards,

Jos
Ohh, thanks for reminding.... yah, your right...

Jos, for example, i have a class that was executed by JVM...

Can i get the directory were my executed class exists without using file?
I mean File Class?

Is it possible?

Or that was the last option?!!


Sukatoa...
Mar 14 '08 #4
JosAH
11,448 Expert 8TB
Ohh, thanks for reminding.... yah, your right...

Jos, for example, i have a class that was executed by JVM...

Can i get the directory were my executed class exists without using file?
I mean File Class?

Is it possible?

Or that was the last option?!!


Sukatoa...
There's also the FileSystemView class but it's similar to the File() solution.

kind regards,

Jos
Mar 14 '08 #5
sukatoa
539 512MB
There's also the FileSystemView class but it's similar to the File() solution.

kind regards,

Jos

I got it...

Sukatoa...
Mar 14 '08 #6
dmjpro
2,476 2GB
You don't even have to create a real file for that; an abstract pathname is enough:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
You do have to handle potential IOExceptions.

kind regards,

Jos
Thank you JOS ...but If I want to change that path then is it possible?

Debasis Jana.
Mar 14 '08 #7
JosAH
11,448 Expert 8TB
Thank you JOS ...but If I want to change that path then is it possible?

Debasis Jana.
I wrote you that already: set the "user.dir" property in the system properties.
Please read some relevant stuff first and only then ask: it's all in the File API
documentation. Here is my previous post.

kind regards,

Jos
Mar 14 '08 #8
dmjpro
2,476 2GB
I wrote you that already: set the "user.dir" property in the system properties.
Please read some relevant stuff first and only then ask: it's all in the File API
documentation. Here is my previous post.

kind regards,

Jos

Thanks a lot!

Debasis Jana!
Mar 14 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: EAS | last post by:
Does anyone know how to display the current directory using DOS and/or Python? I already tried os.pardir and os.curdir in Python, but all they return are a couple of periods... >>>import os...
3
by: Daniel | last post by:
How do you get the current directory of the actual .exe file (not the file name but the directory it is in) ? These do not work: System.IO.Directory.GetCurrentDirectory() - returns system...
11
by: kk | last post by:
Can any function tell the compiled program executing path? after using the program to open a file from MFC dialog box, the path changes. thks in advance.
3
by: Alur | last post by:
Changing the current directory with the help of dialog window(MFC app) We can change directory with the help of the following code: CFileDialog m_ldFile(TRUE);...
3
by: Progman | last post by:
I use Visual Studio 2005 When I run msgbox Curdir(), I get the visual studio directory. This problem seems to be only in the VB part. In the ASP, we use ~/etc... to access files. Why I...
3
by: Chris Mellon | last post by:
This appears to be a change in behavior from Python 2.4 to Python 2.5, which I can't find documented anywhere. It may be windows only, or related to Windows behavior. In 2.4, the current...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
11
by: greg | last post by:
Hi all, Is there a way to get the current theme name at design time? I'm trying to write a custom control for which I need to use images from the current theme. I have asigned a theme to the...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
2
by: Kakkanattu | last post by:
Hi, In desktop application, we use different ways to get the current execution directory. I. AppDomain.CurrentDomain.BaseDirectory II. Environment.CurrentDirectory...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.