• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

save txt file with file chooser

 
george kartas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
george kartas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic