summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/unit/UnitDatabase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/unitConverter/unit/UnitDatabase.java')
-rw-r--r--src/org/unitConverter/unit/UnitDatabase.java27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/org/unitConverter/unit/UnitDatabase.java b/src/org/unitConverter/unit/UnitDatabase.java
index 9ca9617..000acf5 100644
--- a/src/org/unitConverter/unit/UnitDatabase.java
+++ b/src/org/unitConverter/unit/UnitDatabase.java
@@ -16,12 +16,11 @@
*/
package org.unitConverter.unit;
-import java.io.BufferedReader;
-import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1866,15 +1865,12 @@ public final class UnitDatabase {
* @since 2019-01-13
* @since v0.1.0
*/
- public void loadDimensionFile(final File file) {
+ public void loadDimensionFile(final Path file) {
Objects.requireNonNull(file, "file must not be null.");
- try (FileReader fileReader = new FileReader(file);
- BufferedReader reader = new BufferedReader(fileReader)) {
- // while the reader has lines to read, read a line, then parse it, then
- // add it
+ try {
long lineCounter = 0;
- while (reader.ready()) {
- this.addDimensionFromLine(reader.readLine(), ++lineCounter);
+ for (final String line : Files.readAllLines(file)) {
+ this.addDimensionFromLine(line, ++lineCounter);
}
} catch (final FileNotFoundException e) {
throw new IllegalArgumentException("Could not find file " + file, e);
@@ -1908,15 +1904,12 @@ public final class UnitDatabase {
* @since 2019-01-13
* @since v0.1.0
*/
- public void loadUnitsFile(final File file) {
+ public void loadUnitsFile(final Path file) {
Objects.requireNonNull(file, "file must not be null.");
- try (FileReader fileReader = new FileReader(file);
- BufferedReader reader = new BufferedReader(fileReader)) {
- // while the reader has lines to read, read a line, then parse it, then
- // add it
+ try {
long lineCounter = 0;
- while (reader.ready()) {
- this.addUnitOrPrefixFromLine(reader.readLine(), ++lineCounter);
+ for (final String line : Files.readAllLines(file)) {
+ this.addUnitOrPrefixFromLine(line, ++lineCounter);
}
} catch (final FileNotFoundException e) {
throw new IllegalArgumentException("Could not find file " + file, e);