473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 61073
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.