*
The moose likes Swing / AWT / SWT and the fly likes save txt file with file chooser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "save txt file with file chooser" Watch "save txt file with file chooser" New topic
Author

save txt file with file chooser

george kartas
Greenhorn

Joined: Sep 16, 2012
Posts: 5
Hi am new one here and i would your help
I write a method which save to data.txt some numbers. Now i want to use the Jfilechooser to choose the destination path. How can i connect them??

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4372
    
    8

Hi George. Welcome to the Ranch!

Have you looked at the other constructors for FileWriter? One of them takes a File object, and you've got a File object from your save dialog. So...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

There are other FileWriter constructors, you know. Have you gone through the API?

That said, you should check whether the user clicked "Save" or "Cancel" of the JFileChooser's dialog, and maybe whether the File already exists, unless you intend to overwrite it blindly (not recommended).


luck, db
There are no new questions, but there may be new answers.
george kartas
Greenhorn

Joined: Sep 16, 2012
Posts: 5
Thank you for your answers.It was helpful.
I changed the data.txt with selfile .

How can i have a standard name for my saved files?? For example data.txt???
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

george kartas wrote:Thank you for your answers.It was helpful.

Glad we could help.

george kartas wrote:How can i have a standard name for my saved files?? For example data.txt???

We seem to be going round in circles here...
george kartas
Greenhorn

Joined: Sep 16, 2012
Posts: 5

We seem to be going round in circles here...


You have a point here and i apologize for that. I want to choose the path of my text file and the name to be standard.
Is there a way to do that?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

See the file selection modes you can set of a file chooser. Have you gone through the tutorial linked from the API?
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

george kartas wrote:Thank you for your answers.It was helpful.
I changed the data.txt with selfile .

How can i have a standard name for my saved files?? For example data.txt???


The JFileChooser class has the method setSelectedFile() which you may need.


PM Me If You Want to get Urgent Help on Java Programming
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Nam Ha Minh wrote:The JFileChooser class has the method setSelectedFile() which you may need.

No, that's not what was being asked here.
george kartas
Greenhorn

Joined: Sep 16, 2012
Posts: 5
That said, you should check whether the user clicked "Save" or "Cancel" of the JFileChooser's dialog, and maybe whether the File already exists, unless you intend to overwrite it blindly (not recommended).


That was great warning.Thanks.
Have you gone through the tutorial linked from the API?


I'm new one in java . So which API do you mean??

I have a new problem with my application...


With this method i try to import the data from a text file into jtable1 and jtable2.The text file is the one that i create with previous method.
The text file data is


How can i import the data with this form without sentence "# jtable2" and not the above display??
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

george kartas wrote:
Have you gone through the tutorial linked from the API?


I'm new one in java . So which API do you mean??


He meant the one which the API documentation links to.

Evidently you haven't yet found out about the API documentation. You'll find it's a lot easier to write code if you have access to the documentation of the classes you're going to use. And you do have access to it. Follow this link: JFileChooser (<== that's a link, click on it) and you'll be looking at the API documentation for JFileChooser. And you'll find, very near the top, a link to a tutorial.

You'll also find that the Google keywords JFileChooser tutorial lead you to that tutorial, but it takes a little bit of care to pick it out of all of the other links you get. If you look for it that way (I always google for "java x tutorial" if I want to know about X in Java) then pick tutorials from Oracle in preference to others.
george kartas
Greenhorn

Joined: Sep 16, 2012
Posts: 5

He meant the one which the API documentation links to.

Evidently you haven't yet found out about the API documentation. You'll find it's a lot easier to write code if you have access to the documentation of the classes you're going to use. And you do have access to it. Follow this link: JFileChooser (<== that's a link, click on it) and you'll be looking at the API documentation for JFileChooser. And you'll find, very near the top, a link to a tutorial.

You'll also find that the Google keywords JFileChooser tutorial lead you to that tutorial, but it takes a little bit of care to pick it out of all of the other links you get. If you look for it that way (I always google for "java x tutorial" if I want to know about X in Java) then pick tutorials from Oracle in preference to others.


Thanks for your answer and in the most occasions i search about API documentation. But sometimes you need someone else help.


I'm mean here that i don't want to take all the line with 01 but every number separately.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: save txt file with file chooser