GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TextFileReader.java · au55260/Java@740f968

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java-simple-text-file-reader/src/main/java/com/hmkcode
    • TextFileReader.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java-simple-text-file-reader/src/main/java/com/hmkcode/TextFileReader.java‎

Copy file name to clipboard
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.hmkcode;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
8+
public class TextFileReader {
9+
10+
private BufferedReader buffer;
11+
private String currentLine = "";
12+
public TextFileReader(){
13+
14+
}
15+
16+
public void open(String file){
17+
18+
try {
19+
close();
20+
21+
buffer = new BufferedReader(new FileReader(file));
22+
23+
} catch (FileNotFoundException e1) {
24+
e1.printStackTrace();
25+
26+
}
27+
28+
}
29+
30+
public void close(){
31+
32+
try {
33+
if(buffer != null){
34+
buffer.close();
35+
buffer = null;
36+
}
37+
} catch (IOException e) {
38+
e.printStackTrace();
39+
}
40+
41+
}
42+
43+
public String readLine() throws Exception{
44+
if(buffer != null){
45+
currentLine = buffer.readLine();
46+
47+
if(currentLine == null)
48+
close();
49+
50+
return currentLine;
51+
}
52+
else
53+
throw new Exception("No file to read...");
54+
}
55+
56+
public String getCurrent(){
57+
return this.currentLine;
58+
}
59+
60+
public boolean isReadable(){
61+
return (buffer != null && this.currentLine != null);
62+
}
63+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.