• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

writing to a file

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me how i can write a string to a file?
I've already got

but clearly in is an InputStream and saveTable.getText(); is a string. How can i get around this?
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need InputStream in this case at all. You just write a string. Check the methods on FileOutputStream.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better yet, if you are only writing character data, you should use Writers, specifically the BufferedWriter...
String text = "This is text to write to file.";
File = new File("yourfile.whatever");
FileWriter fw = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(fw);
writer.write(text);
writer.close();
FileWriter will do this by itself, but the BufferedWriter povides some buffering for more efficiency.
Hope this helps.
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic