larry clay

Greenhorn
+ Follow
since Mar 18, 2012
larry likes ...
Firefox Browser Windows
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by larry clay

If you want to verify if the file exists you'll need to use the isFile() instance method. Let me try to explain it (i'm also new to java and programming so we're together in this)

You're creating a File instance while creating & initializing the Scanner instance "scan":
Scanner scan = new Scanner(new File(inName));

If you want to work always on the same File you'll need to widen the scope of that instance, i'd suggest you create a null instance at the beginning of main() and then initialize/reinitialize when needed. Remember that File objects work with file and directory pathnames, for more info on the File class methods check this

the code you're looking for it's something like this


12 years ago
Use the File method isFile: returns true if and only if the file denoted by the instance's abstract pathname exists and is a normal file; false otherwise
12 years ago
Thanks for the help and welcome guys!

It works now and this is the corrected snippet. This only works with single extension filefilters since I only do a getExtensions()[0] method call. Filters with multiple extensions won't allow me to know which extension is the chosen one, neither the chosen File path if I don't explicitly name it with the desired extension so I can't do it this way ... I can't come with a workaround to this but neither do I need to implement it now. At least I know a little more about this matter now

12 years ago
Hello guys, I've been testing things for a while since i'm learning java; I'm doing a playlist editor/creator and most of the problems I have are due to swing, and here comes my question. I used JFileChooser to open files without any problem, the FileNameExtensionFilters worked well, but now i'm a bit disoriented about what to do when saving with different file extensions, here's an example code:



This isn't working, it saves files without any extension unless I explicitly include the extension in the name when I select the file to save
I can already tell that the FileNameExtensionFilters only work when selecting files to be opened, but I still haven't figured out yet how to make extensions work. How can I force file extensions when saving according to the selected FileNameExtensionFilter? Any leads on this would be helpful, thanks in advance
12 years ago