-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion.java
More file actions
68 lines (61 loc) · 2.03 KB
/
Version.java
File metadata and controls
68 lines (61 loc) · 2.03 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package my.quarker;
import java.io.*;
import javax.swing.*;
/**
*
* @author ehoward
*/
public class Version{
String fileContents;
JTextArea versionWindow;
JFrame versionFrame;
public Version() {
versionWindow = new JTextArea();
File inputFile = new File(".");
try {
inputFile = new File(System.getProperty("user.dir") + "\\UpdateInfo.txt");
} catch (Exception e) {
e.printStackTrace();
}
fileContents = getContents(inputFile);
versionWindow.setText(fileContents);
versionFrame = new JFrame();
versionFrame.add(versionWindow);
versionFrame.pack();
versionFrame.setLocationRelativeTo(null);
versionFrame.setTitle("About");
versionWindow.setEditable(false);
versionFrame.setVisible(true);
}
static public String getContents(File aFile) {
//...checks on aFile are elided
StringBuilder contents = new StringBuilder();
try {
//use buffering, reading one line at a time
//FileReader always assumes default encoding is OK!
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null; //not declared within while loop
/*
* readLine is a bit quirky :
* it returns the content of a line MINUS the newline.
* it returns null only for the END of the stream.
* it returns an empty String if two newlines appear in a row.
*/
while ((line = input.readLine()) != null) {
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
} finally {
input.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return contents.toString();
}
}