how to read in a file as one whole String

Hi..im trying to read in a file, that has white spaces, indenting and all..an i wana read in all that as one string. i cant use realine has it reads in line by line...someone told me i should use fileinputstream but i dont knw how that's done. thanks
[258 byte] By [tripper1984a] at [2007-10-3 1:02:13]
# 1
You could use readLine() and append all the Strings.
aniseeda at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 2

> Hi..im trying to read in a file, that has white

> spaces, indenting and all..an i wana read in all that

> as one string. i cant use realine has it reads in

> line by line...someone told me i should use

> fileinputstream but i dont knw how that's done. thanks

Code removed because the OP is more interested in arguing than in solving his problem.

Message was edited by:

sabre150

Message was edited by:

sabre150

sabre150a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 3

yea but i dont want to do that coz i have the reading in file in my main class. and a separte function that looks for two specific words in that whole string and spits out the content between them. with readline its only line by line.. my main looks like this:

public static void main(String args[])

{

try

{

FileInputStream fstream = new FileInputStream("c:/Program Files/searchResult.xml");

String line;

line = fstream.toString();

System.out.println (line);

fstream.close();

}

catch (Exception e)

{

System.err.println("error");

}

}...

So right now all this does is reads in the file..but the output it gives me is :

java.io.FileInputStream@108786b

any ideas?

tripper1984a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 4
I think the official way is:new Scanner(file).useDelimiter("\\z").next()
IanSchneidera at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 5
WAIT A MINUTE... are you that failed intern that tortured everyone with your "PDF in a file" problem?DONT CROSS POST! http://forum.java.sun.com/thread.jspa?threadID=753742&tstart=50
TuringPesta at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 6
a separte function that> looks for two specific words in that whole string and> spits out the content between them. Do you mean that you wish to split the file into three based on two marker words?
sabre150a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 7
no buddy. This is a different one. and besides im in a different forum, coz i realized i should have posted here(new to java) in the first place. ur the one whos corssposting your reaction. if you have any solutions then good, if not then i dont care much for your anger
tripper1984a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 8

> yea but i dont want to do that coz i have the reading

> in file in my main class. and a separte function that

> looks for two specific words in that whole string and

> spits out the content between them. with readline its

> only line by line.. my main looks like this:

Monkey, if this is your new scheme for locating %PDF and %%EOF in a file - we already helped you with this. Dont read the entire file as a string. I dont understand what is so difficult.

TuringPesta at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 9
umm no..just the one, the content that is between the two marker words
tripper1984a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 10

> no buddy. This is a different one. and besides im in

> a different forum, coz i realized i should have

> posted here(new to java) in the first place. ur the

> one whos corssposting your reaction. if you have any

> solutions then good, if not then i dont care much for

> your anger

I'm going to *mildly* point out that posting in a different forum is what "crossposting" means. Just a thought.

cdelmioa at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 11
im sorry i didnt get that solution turningpest..too advanced for me. which is why im here..
tripper1984a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 12

First: spell out words. cuz, b4, ur...

Second: "no buddy. This is a different one." Your saying in THIS thread that you are looking for 2 markers in a text file and you want the stuff in between. This is almost EXACTLY your problem from yesterday.

The reason people dont like crossposting isnt because we are mean or "angry" people... its b.c. people worked hard to help you yesterday and its not fair to other people today to have to repeat that whole ordeal. Not to mention you never awarded Dukes to the people that did assist you.

TuringPesta at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 13
i also mentioned,, that i realized I had to go "New in java" forum ok?the other one whatever its called is for advaned programmers..i dont wana hear ur naggin awrite...if u wana offer me some solution good..if not mind ur own buisness..
tripper1984a at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 14

> ..if not mind ur own buisness..

Im just explaining the etiquette of the forums to you.

No one is getting paid to help you - so you should at least give

them your respect. Crossposting is considered inconsiderate.

And using abbreviations like "ur, cuz, b4..." just bother people and make

you look dumb.

TuringPesta at 2007-7-14 17:58:20 > top of Java-index,Java Essentials,New To Java...
# 15

> no buddy. This is a different one. and besides im in

> a different forum, coz i realized i should have

> posted here(new to java) in the first place. ur the

> one whos corssposting your reaction. if you have any

> solutions then good, if not then i dont care much for

> your anger

It might help if you actually read what has been written! Up to a point I don't mind being ignored but you seem to be turning it into an art form.

sabre150a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 16
Sorry sabre.. i basically need to have one part of the file which is between the two marker words.(replying to your earlier post)
tripper1984a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 17
> First: spell out words. cuz, b4, ur...> Ummm.> The reason people dont like crossposting isnt because> we are mean or "angry" people... its b.c. people
cotton.ma at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 18
bite me, lol.Hartman's Law of Prescriptivist Retaliation - "any statement about correct grammar, punctuation, or spelling is bound to contain at least one eror". http://en.wikipedia.org/wiki/Hartman%27s_law
TuringPesta at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 19

> Sorry sabre.. i basically need to have one part of

> the file which is between the two marker

> words.(replying to your earlier post)

In response to a very similar problem, I posted a KMP implementation a week or so ago that will allow you to do this with little or no effort.

sabre150a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 20
Thanks sabre. Problem is i dont have access to your posts which are atleast two days old. So if its not much trouble, maybe you can look up ur post history, and paste it here.Thanks
tripper1984a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 21

> Thanks sabre. Problem is i dont have access to your

> posts which are atleast two days old. So if its not

> much trouble, maybe you can look up ur post history,

> and paste it here.

> Thanks

Would you like a refreshing soda while you wait for that?

prometheuzza at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 22

> > Thanks sabre. Problem is i dont have access to

> your

> > posts which are atleast two days old. So if its

> not

> > much trouble, maybe you can look up ur post

> history,

> > and paste it here.

> > Thanks

>

> Would you like a refreshing soda while you wait for

> that?

Yes!

cotton.ma at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 23
> Thanks sabre. Problem is i dont have access to your> posts which are atleast two days old. So if its not> much trouble, maybe you can look up ur post history,> and paste it here.> You have just the same access as I have!
sabre150a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 24
if i click on your profile i see all the posts you posted in the last couple days. Is that what you see too?
tripper1984a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 25
> Yes!I'm sorry sir, I was addressing the OP. I will be right with you.
prometheuzza at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 26
> > Yes!> > I'm sorry sir, I was addressing the OP. > I will be right with you.I'll have an iced tea on your way back, waiter.
cdelmioa at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 27
Tripper, Sabre went out of his way to find that KMP link for you in another thread. You should appreciate it and give him some Duke dollars.
TuringPesta at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 28
Turingpest..whats the deal with that name anyway? well you r pesting me for sure..anwasy this post didnt have any duke dollars to begin with. and i knw their not worth anything..i wouldnt mind sending him real dollars to tell you the truth
tripper1984a at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 29
> > > Yes!> > > > I'm sorry sir, I was addressing the OP. > > I will be right with you.> > I'll have an iced tea on your way back, waiter.and I'll have some cough syrup, waiter.
aniseeda at 2007-7-21 9:25:30 > top of Java-index,Java Essentials,New To Java...
# 30

> Turingpest..whats the deal with that name anyway?

> well you r pesting me for sure..anwasy this post

> didnt have any duke dollars to begin with. and i knw

> their not worth anything..i wouldnt mind sending him

> real dollars to tell you the truth

It's better to be a turning pest than to be a tripper.

aniseeda at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 31
aniseed..u wouldnt knw unless ur trippin my buddy
tripper1984a at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 32
> aniseed..u wouldnt knw unless ur trippin my buddyWell, this is certainly getting intelligent.Waiter?
cdelmioa at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 33

> Turingpest..whats the deal with that name anyway?

http://en.wikipedia.org/wiki/Turing_test

> well you r pesting me for sure..anwasy this post

> didnt have any duke dollars to begin with.

assign some.

> and i knw

> their not worth anything..i wouldnt mind sending him

> real dollars to tell you the truth

the Duke dollars are a symbolic sign of appreciation.

Go here for that KMP implementation:

http://forum.java.sun.com/thread.jspa?threadID=754144&tstart=0

If you were less of a tool I probably wouldve written out that pseudo-code from your last post. I get paid a lot of $ to write code but none to help the ungrateful, lol.

TuringPesta at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 34
> aniseed..u wouldnt knw unless ur trippin my buddyI see a lot of alphabets got tripped in the transmission.
aniseeda at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 35
> aniseed..u wouldnt knw unless ur trippin my buddyThis post unsatisfactorily dismooded me with the many many doubts it raised.
cotton.ma at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 36
> > aniseed..u wouldnt knw unless ur trippin my buddy> > Well, this is certainly getting intelligent.> Waiter?Sorry ma'am, that iced latte will be right there!
prometheuzza at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 37

> > > aniseed..u wouldnt knw unless ur trippin my

> buddy

> >

> > Well, this is certainly getting intelligent.

> > Waiter?

>

> Sorry ma'am, that iced latte will be right

> there!

*sigh*.... of course it will. Am I really not allowed to *not* drink coffee around here?

cdelmioa at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 38

> > > > Yes!

> > >

> > > I'm sorry sir, I was addressing the OP.

> > > I will be right with you.

> >

> > I'll have an iced tea on your way back, waiter.

>

> and I'll have some cough syrup, waiter.

Excellent choice, sir! I see we have a connaisseur in our establishment.

May I recommend the bottle from 1974?

prometheuzza at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 39
I really have to change my username. TuringPest is starting to bother me too, lol.Any ideas for a new one?
TuringPesta at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 40
Thanks for your help guys, sabre,prometheuzz,..and a very special thanks to teringpost...uv been the greatest help of all!!
tripper1984a at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 41
> I really have to change my username. > TuringPest is starting to bother me too, lol.> Any ideas for a new one?Pestering***;)
aniseeda at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 42

> > > > > Yes!

> > > >

> > > > I'm sorry sir, I was addressing the OP.

> > > > I will be right with you.

> > >

> > > I'll have an iced tea on your way back, waiter.

> >

> > and I'll have some cough syrup, waiter.

>

> Excellent choice, sir! I see we have a connaisseur in

> our establishment.

> May I recommend the bottle from 1974?

Ah! certainly :D

aniseeda at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 43
> Thanks for your help guys, sabre,prometheuzz,..> and a very special thanks to teringpost...uv been the> greatest help of all!!Sir, SIR!!! You forgot to pay your bill.
prometheuzza at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 44
>> uv been the greatest help of all!! Do you mean that, lol. Wow. Ill actually write that code out for you if you need it - but youll have to keep the humility, lol.
TuringPesta at 2007-7-21 9:25:35 > top of Java-index,Java Essentials,New To Java...
# 45

> i also mentioned,, that i realized I had to go "New

> in java" forum ok?

> the other one whatever its called is for advaned

> programmers..i dont wana hear ur naggin awrite...if u

> wana offer me some solution good..if not mind ur own

> buisness..

cn u plz writ in rl englsh?

Cripes. Illiterate bozo.

jverda at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 46
gimme ur address guys..il mail em out to u
tripper1984a at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 47
Email us what?
TuringPesta at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 48
> Email us what?Shh-- payment for the bill, silly.
cdelmioa at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 49
> gimme ur address guys..il mail em out to uSure, why notspambot@sucker.com
aniseeda at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 50
> > Email us what?> > Shh-- payment for the bill, silly.<sotto-voce>Should it not be Paypal?</sotto-voce>
aniseeda at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 51
Ahem, actually, if you check with the waiter, I believe this establishment takes credit cards.
cdelmioa at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 52
I take coupons to Taco Bell.
TuringPesta at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 53
k people..i meant HOME addresses..and i said il mail money out..NOT EMAIL!!
tripper1984a at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 54
> k people..i meant HOME addresses..and i said il mail> money out..NOT EMAIL!!:shock:I'm almost convinced he's serious.
cdelmioa at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 55
send it to:Mr. Travis Bickle123 Fake StreetBrooklyn, NY 100123
TuringPesta at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 56
Ooh, and to:Cobe delMio42 PetiteVilleMidNowhere, Eastern CanadaB10 2H5
cdelmioa at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...
# 57

Travis Bickle... "Gods lonely man", lol.

http://en.wikipedia.org/wiki/Travis_Bickle

What was the fake name he gave the secret service guy on the street?

Robert DeNiro (Travis): You talkin' to me? You talkin' to me? You talkin' to me? Then who the h*ll else are you talkin' to? You talkin' to me? Well I'm the only one here. Who do you think you're talking to? Oh yeah? Huh? Ok.

TuringPesta at 2007-7-21 9:25:40 > top of Java-index,Java Essentials,New To Java...