Forums Register Login

Saving a File

+Pie Number of slices to send: Send
Hello.
How would i write code to save a file. Example, i want the code to be able to take the data just manipulated and save it to a file.
Ideally i want the screen to have a popup menu that can let you type in a file name and hit save...this will save your file to your destination. How would i code this saving process.
thank you in advance, Nikki
+Pie Number of slices to send: Send
To answer the first part of the question :
assume that you have your data stored in a string aString, if it is not, you can always find a way to map it into a string representation.
Now you can do :
import java.io.*;
try{
RandomAccessFile rafOut = new RandomAccessFile("whateverPath" + File.separator + "whateverFileName", "rw");
rafOut.writeBytes(aString);
rafOut.close();
}catch(IOException ex){
ex.printStackTrace();
}
or
FileOutputStream fileOut = new FileOutputStream("whateverPath etc...");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileOut));
writer.write(aString, 0, aString.length());
writer.flush();
writer.close();
fileOut.close();
}catch(IOException etc){
}
Now about the second question : see javax.swing.JFileChooser
good luck
[This message has been edited by Omar IRAQI (edited July 18, 2001).]
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 900 times.
Similar Threads
saving JTree
Saving a File
running an executable file on the server by client
Help on how to change caption of Confirm box in JSP
save with JFileChooser
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:03:28.