Results 1 to 2 of 2
- 12-22-2011, 04:08 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 1
- Rep Power
- 0
Extension problem using JFileChooser
Hello,
Can anyone please help me with this? I'm using a JFileChooser to create new files, I want it to save them in a ".txt" format, the problem is the user has to explicitely add ".txt" to his file name, otherwise it will save it as "what_the_user_has_typed" without any extension...
and after I recover the filename the user has typed, there's no function to change the name as "setName"
And the renameTo(new File()); fails, can I program it so it automatically adds the ".txt" extension to what the user has typed?Java Code:File file = new File(); file.setName(file.getName()+".txt");
Thank you :)
- 12-22-2011, 04:44 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Extension problem using JFileChooser
What aboutafter I recover the filename the user has typed, there's no function to change the name as "setName"
where file is as returned by the dialog, and newName is the name you would prefer to use.Java Code:file = new File(file.getParent(), newName);
-----
Strictly speaking ".txt" is an extension not a format; files are like roses in this respect.
This isn't just a quibble. It's up to your program what format you save a file in, but you should be a bit careful about rejecting the name that the user wishes to give it. I don't appreciate the likes of Notepad being "helpful". Perhaps add a checkbox "add .txt" or something, and respect the filename if it has a . in it.
Similar Threads
-
JFileChooser Problem
By gkoef in forum New To JavaReplies: 5Last Post: 04-29-2011, 02:08 PM -
Problem with saving from JFileChooser
By fireshadow4126 in forum AWT / SwingReplies: 2Last Post: 11-24-2010, 08:21 PM -
Problem with JFileChooser and BufferedImage Class
By toro1984 in forum AWT / SwingReplies: 3Last Post: 11-03-2010, 10:09 AM -
JFileChooser problem
By jperson in forum New To JavaReplies: 2Last Post: 02-06-2010, 07:31 PM -
jfilechooser and jtextarea problem
By kostinio in forum AWT / SwingReplies: 7Last Post: 10-07-2009, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks