I was wondering how to get java to save a text file named hello.txt to the desktop without writing
"C:\\Users\\Austin\\Desktop"
Any help would be great. so like:
FileWriter fileWriter = new FileWriter(fileName.getText(), true);
..and the fileName.getText() is just going to be the ‘hello’.
UPDATE:
i think that i would be able to use the jfilechooser, so would this work?
JFileChooser chooser = new JFileChooser();
chooser.setVisible(true);
would that work? and if so, how would i get it to save the file using the selection in there?
im a noob…. 🙁
I forgot different Locales. Very fragile code (even for code that starts out OS specific). See my comment below re. OS X/
JFileChooser.Oracle helpfully provides docs for this kind of thing.
See
System.getProperty(String)&new File(String,String).I’ll cede to an expert (or a user) on this, but I don’t think OS X supports any application icons or document icons directly on the ..start screen, default look, whatever.. Probably better to offer the end user a
JFileChooserpointing touser.homeand ask them to save the document to the desktop (or wherever they feel like).