Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there an efficient way to read a text file into a string?

 
Tong Chen
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there an efficient way to read a text file into a string? or anybody can give me a sample code?
Thanks,
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Presizing the StringWriter is optional, but improves performance. Here I assumed that the file encoding was one byte per character. If that's not the case you may wish to presize differently - e.g. for UTF-16 use
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic