Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

saving an output file

Thread view: 
aeh - 27 Jun 2005 14:54 GMT
Hi,

Is there any way to save the output file to a user specified directory?
I would like for the user to be able to select a directory and save the
output file there. At the very least, is there any way to specify where
the file is saved by writing it into the code. I know that in C++ you
can specify where the file is created by doing something like this
"C:\\mydir\myprogram.cpp" when you name the file. Does Java allow
something like this?
Andrew Thompson - 27 Jun 2005 15:01 GMT
> Is there any way to save the output file to a user specified directory?
> I would like for the user to be able to select a directory and save the
> output file there.

See FileDialog[1] or JFileChooser[2].

[1] <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/FileDialog.html>
[2] <http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFileChooser.html>

>..At the very least, is there any way to specify where
> the file is saved by writing it into the code.

Their is no place like System.getProperty("user.home")  [3]

[3]
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getProperty(java.l
ang.String
)>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Ingo R. Homann - 27 Jun 2005 15:04 GMT
Hi aeh,

> Hi,
>
[quoted text clipped - 5 lines]
> "C:\\mydir\myprogram.cpp" when you name the file. Does Java allow
> something like this?

In javax.swing, there is a class called JFileChooser (with the
possibility to select a directory instead of a file), and the other
Windowing-Frameworks provide a similar functionality, I guess.

For saving the File, java.io will help.

Ciao,
Ingo
Leon - 27 Jun 2005 15:15 GMT
> Hi,
>
> Is there any way to save the output file to a user specified directory?
> I would like for the user to be able to select a directory and save the
> output file there.

Look at documentation about

javax.swing.JFileChooser;
javax.swing.filechooser.FileFilter;

> At the very least, is there any way to specify where
> the file is saved by writing it into the code. I know that in C++ you
> can specify where the file is created by doing something like this
> "C:\\mydir\myprogram.cpp" when you name the file. Does Java allow
> something like this?

Yes. By using "test.txt" you use the current directory. "C:\\mydir\\test.txt"
specifies the absolute filename.

Greetings, Leon.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.