Skip to content

Commit b569ee5

Browse files
authored
Change to string function (#33)
Changed text file to string. Try with resources auto-closes bufferedreaders so you don't need finally. In the previous code the stringBuilder was scoped to the try so it wasn't visible outside of that for the last line. A catch printing the exceptions is always nice to have.
1 parent b1ab1b7 commit b569ee5

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,17 @@ First you need to turn your ink file into a json file [as described here](https:
1212

1313
```java
1414
InputStream systemResourceAsStream = ClassLoader.getSystemResourceAsStream(filename);
15+
StringBuilder sb = new StringBuilder();
1516

16-
BufferedReader br = new BufferedReader(new InputStreamReader(systemResourceAsStream, "UTF-8"));
17-
18-
try {
19-
StringBuilder sb = new StringBuilder();
17+
try (BufferedReader br = new BufferedReader(new InputStreamReader(systemResourceAsStream, "UTF-8"));){
2018
String line = br.readLine();
21-
2219
while (line != null) {
2320
sb.append(line);
2421
sb.append("\n");
2522
line = br.readLine();
2623
}
27-
28-
} finally {
29-
br.close();
30-
}
24+
}
25+
catch(Exception e){e.printStackTrace();}
3126

3227
String json = sb.toString().replace('\uFEFF', ' ');
3328
```

0 commit comments

Comments
 (0)