-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadVersionFile.java
More file actions
31 lines (29 loc) · 1.11 KB
/
Copy pathReadVersionFile.java
File metadata and controls
31 lines (29 loc) · 1.11 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
package io.github.project516.NumberGuessingGame;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/** Reads version information for the Number Guessing Game from the version.txt resource file. */
public class ReadVersionFile {
/**
* Retrieves the current version of the game by reading from the version.txt resource file.
*
* @return the version string
*/
public String readVersion() {
String content = "1.0.0"; // Default fallback version
try (InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("version.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
if (inputStream != null) {
content = reader.readLine();
if (content != null) {
content = content.trim();
}
}
} catch (IOException e) {
System.err.println("Error reading version file: " + e.getMessage());
}
return content;
}
}