Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tyhjä #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@

[Travis](https://travis-ci.org/Mahtimursut/ohtu)





24 changes: 14 additions & 10 deletions ReferenceLibrary/src/main/java/referencelibrary/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ public static String Read(String fileName) {
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Olisi mukavaa jos tämäkin rivi olisi uuden metodin sisällä. Tällöin olisi myös metodissa tarve yhtä vähemmälle parametrille ja se tekisi kokonaan lukemisen readerista builderiin.

if (line != null) {
sb.append(line);
}

line = br.readLine();
while (line != null) {
sb.append(System.lineSeparator());
sb.append(line);
line = br.readLine();
}
readlines(line, sb, br);
return sb.toString();
} catch (IOException ex) {
System.out.println("Could not read " + fileName + ": " + ex.getMessage());
}
return null;
}

private static void readlines(String line, StringBuilder sb, final BufferedReader br) throws IOException {
if (line != null) {
sb.append(line);
}

line = br.readLine();
while (line != null) {
sb.append(System.lineSeparator());
sb.append(line);
line = br.readLine();
}
}
}