Java Example - Reading File Content
The following example demonstrates how to use the readLine() method to read the content of the file test.log, where the content of test.log is:
Runoob Tutorial
www.runoob.com
The Java code is as follows:
Main.java File
import
java
.
io
.*;
public
class
Main
{
public
static
void
main
(
String
[
]
args
)
{
try
{
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
"
test.log
"
)
)
;
String
str
;
while
(
(
str
=
in
.
readLine
(
)
)
!=
null
)
{
System
.
out
.
println
(
str
)
;
}
System
.
out
.
println
(
str
)
;
}
catch
(
IOException
e
)
{
}
}
}
The output of the above code is:
Runoob Tutorial
www.runoob.com
null
Java Examples