| Author |
InputStreamReader
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
I want to read mytext.txt line by line, As string, Without using any buffer class or buffer array. How to do that?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
What is the indication for a new line? If you can answer that question, simply read the characters until you reach that indication.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
Use a FileReader rather than an input stream for a text file.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
I disagree. FileReader uses the system encoding; this is the proper way to read from a file using a specific encoding, in this case UTF8.
In fact, FileReader extends InputStreamReader; its constructors each call super(new FileInputStream(arg)) where arg is the argument to the constructor.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
Agree: Rob is right.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
. . . but I don't think it's "UTF8". I think it's "UTF-8", but you would have to check carefully, maybe here.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
In Java you can use both for charsets. One is an alias for the other, but I can't remember which way around it is.
|
 |
Kurosaki Ichigo
Greenhorn
Joined: Dec 31, 2010
Posts: 10
|
posted

0
|
i am not sure why, but why can't you use the Scanner?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
Rob Prime wrote:In Java you can use both for charsets. One is an alias for the other, but I can't remember which way around it is.
Thank you. Wasn't certain about that. I think the official name is UTF-8, so UTF8 would be the alias.
|
 |
 |
|
|
subject: InputStreamReader
|
|
|