aspose file tools*
The moose likes I/O and Streams and the fly likes Is there an efficient way to read a text file into a string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Is there an efficient way to read a text file into a string?" Watch "Is there an efficient way to read a text file into a string?" New topic
Author

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

Tong Chen
Ranch Hand

Joined: Apr 26, 2002
Posts: 1011
Hi,
Is there an efficient way to read a text file into a string? or anybody can give me a sample code?
Thanks,


Tong Chen (Seattle USA)<br />SCJP,SCWCD,SCDJWS,IBM XML,MCP.NET,MCAD.NET,MCSD.NET
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671

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


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there an efficient way to read a text file into a string?