Skip to content

Commit

Permalink
use Paths library, raise readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Cady Wang committed Dec 10, 2016
1 parent 286736f commit 1c99a55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ consecutive in text.

`java FileProcessor <Path for My Clippings.txt> <Directory to store separated notes>`

**Source Clippings file format**
####Source Clippings file format
![Source Clippings file format](./src/pics/Before.png)

**Parsed Notes format**

####Parsed Notes format
![Parsed Notes format](./src/pics/After.png)
7 changes: 5 additions & 2 deletions src/FileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -82,7 +83,8 @@ private List<NoteItem> aggregateNotes(List<NoteItem> noteItemList) {
}

private void writeFile(String filePath, List<NoteItem> noteItemList) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(filePath + noteItemList.get(0).getTitle() + ".txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter(Paths.get(filePath,
noteItemList.get(0).getTitle() + ".txt").toString()));

for (int i = 0; i < noteItemList.size() - 1; i++) {
NoteItem item = noteItemList.get(i);
Expand All @@ -91,7 +93,8 @@ private void writeFile(String filePath, List<NoteItem> noteItemList) throws IOEx

if (!item.getTitle().equals(nextItem.getTitle())) {
writer.close();
writer = new BufferedWriter(new FileWriter(filePath + nextItem.getTitle() + ".txt"));
writer = new BufferedWriter(new FileWriter(Paths.get(filePath,
nextItem.getTitle() + ".txt").toString()));
}
}
writer.write(noteItemList.get(noteItemList.size() - 1).toString());
Expand Down

0 comments on commit 1c99a55

Please sign in to comment.