Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Writing to file...

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!
What is the best (concerning performance) way to write Strings to a file? Is it
----
FileWriter fw = new FileWriter("fil.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("En rad.");
bw.newLine();
bw.close();
----
or is it
----
FileOutputStream fos = new FileOutputStream("fil.txt");
PrintStream ps = new PrintStream(fos);
ps.println("Tjena!");
ps.close();
----
or is perhaps the best way some completely other way???
Which one to choose?
//Kaspar
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just out of curiosity, why wouldn't you ask such a question in the Performance forum?
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, hrrm...
I thought about it. But then I figured that it is a basic thing to write output to a file, so I thought that you could have a go at it.
Nobody has told me the 'perfect' way of doing this, and I wonder if there is one. Is there?
And secondly, before I knew it, my fingers had already submitted the post, and I know the severe punishments for crossposting...
//Kaspar
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! 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