472,805 Members | 972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Reading a text file into a string in one operation

Is there a neat way to read the entire contents of a file into a string
without having to write a read() loop each time? I would have thought
there would be some stream that has a method that lets you read the
entire stream into a string with one line of code, but haven't been able
to find one. Now, this is pretty easy to write myself, but it would be
nicer to use some standard method for such a fundamental operation...

Rune
Jul 17 '05 #1
4 61041
Perhaps this might help you out
its using what you want to avoid but show you how to make a method for it:
http://www.javazoid.com/foj_file.html

On Mon, 17 May 2004 00:27:48 +0200, Rune Berge <ru**@krokodille.com> wrote:
Is there a neat way to read the entire contents of a file into a string
without having to write a read() loop each time? I would have thought
there would be some stream that has a method that lets you read the
entire stream into a string with one line of code, but haven't been able
to find one. Now, this is pretty easy to write myself, but it would be
nicer to use some standard method for such a fundamental operation...

Rune


--
// Daniel Jensen Aka. Daniboy
Da******@456believeit131hotmail.com
Jul 17 '05 #2
Daniel Jensen wrote:
Perhaps this might help you out
its using what you want to avoid but show you how to make a method for it:
http://www.javazoid.com/foj_file.html


Thanks, but I know how to make a method for it. I just wanted to know
whether such a method already exists. However, the article states that
such a method does, in fact, NOT exist, so you indirectly answered my
question anyway :)
Rune
Jul 17 '05 #3
"Rune Berge" <ru**@krokodille.com> wrote in message
news:0T**********************@news000.worldonline. dk...
Is there a neat way to read the entire contents of a file into a string
without having to write a read() loop each time? I would have thought
there would be some stream that has a method that lets you read the
entire stream into a string with one line of code, but haven't been able
to find one. Now, this is pretty easy to write myself, but it would be
nicer to use some standard method for such a fundamental operation...

Rune


If you can guarantee the maximum length of the file or don't mind using
absurdly large buffers (and possibly increasing the maximum heap size) you
could do some type of buffered read.
Jul 17 '05 #4
Bob

"Rune Berge" <ru**@krokodille.com> wrote in message
news:0T**********************@news000.worldonline. dk...
Is there a neat way to read the entire contents of a file into a string
without having to write a read() loop each time? I would have thought
there would be some stream that has a method that lets you read the
entire stream into a string with one line of code, but haven't been able
to find one. Now, this is pretty easy to write myself, but it would be
nicer to use some standard method for such a fundamental operation...

in a word. Perl.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
4
by: Nina | last post by:
Hi everyone, Do you know why the following code only read certain number of lines of text file, but not the entire file? Dim sr As StreamReader Dim str As String Dim al As ArrayList = New...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
1
by: John | last post by:
I have a process that reads a text file then uploads the data into a database table. The text file has 10 lines at the end of the file that are blank BUT it appears that the enter key or space bar...
1
by: JM | last post by:
Hi, I have been trying to read a file, using "StreamReader" to pass the info to an string that is: ....dim stream as new FileStream(file,...) dim sr as new StreamReader(stream) dim data as...
3
by: jasvinder singh | last post by:
Respected Sir/madam, Can you help in providing code in 'C' for Reading text file with n number of rows and columns and putting the result in arrays.The sample file is as follows: rim_label =...
4
by: chetah | last post by:
bd.txt D2333 How to program in Java r IN 454554 Dietal & Dietal Prentice Hall G4547 Java in a Nut Shell c 343345 David Flagman O'Reilly 03-02-08 END 678764 John Smith...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.