Skip to content

Commit bc5ed90

Browse files
util/PropertiesLoader: On setFile test first if file exists, if not throws a FileNotFoundException.
1 parent 83a0f41 commit bc5ed90

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/java/pt/lsts/neptus/util/PropertiesLoader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@
3232
*/
3333
package pt.lsts.neptus.util;
3434

35+
import java.io.File;
3536
import java.io.FileInputStream;
3637
import java.io.FileNotFoundException;
3738
import java.io.FileOutputStream;
3839
import java.io.IOException;
3940
import java.io.InputStream;
4041
import java.io.OutputStream;
42+
import java.nio.file.Files;
43+
import java.nio.file.Path;
44+
import java.nio.file.Paths;
4145
import java.util.Properties;
4246

4347
import pt.lsts.neptus.NeptusLog;
@@ -142,7 +146,11 @@ public void setFile(InputStream in) throws IOException {
142146
* @param txfile Nome do ficheiro dos <i>properties </i>.
143147
*/
144148
public void setFile(String txfile) throws FileNotFoundException, IOException {
145-
InputStream in = new FileInputStream(txfile);
149+
File fx = new File(txfile);
150+
if (!fx.exists()) {
151+
throw new FileNotFoundException(txfile);
152+
}
153+
InputStream in = Files.newInputStream(Paths.get(txfile));
146154
setFile(in);
147155
}
148156

0 commit comments

Comments
 (0)