FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Tutorials/Java/ReadFile/ReadFileJava.java at master · jayaike/Tutorials · GitHub
jayaike
/
Tutorials
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
6
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Tutorials
/
Java
/
ReadFile
/
ReadFileJava.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (26 loc) · 982 Bytes
Breadcrumbs
Tutorials
/
Java
/
ReadFile
/
ReadFileJava.java
Copy path
File metadata and controls
32 lines (26 loc) · 982 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
java
.
io
.
File
;
import
java
.
io
.
IOException
;
import
java
.
util
.
Scanner
;
public
class
ReadFileJava
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
try
{
readFile
(
"<ABSOLUTE OR RELATIVE PATH HERE>"
);
}
catch
(
IOException
err
) {
System
.
out
.
println
(
err
.
getMessage
());
}
}
public
static
void
readFile
(
String
filePath
)
throws
IOException
{
// Declare a file with the given file path (can be relative or absolute)
File
file
=
new
File
(
filePath
);
// Use the file as an input for the scanner class
// which will enable us open and read its contents
Scanner
scnr
=
new
Scanner
(
file
);
// While the txt file still has content (a new line in this case),
// print out the next line
while
(
scnr
.
hasNextLine
()) {
System
.
out
.
println
(
scnr
.
nextLine
());
}
// Close the scanner and free up resources
scnr
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL