Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Saving a File

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic