Add a file input/output helper
This commit is contained in:
parent
ba02ef8f7e
commit
35f4e96805
1 changed files with 25 additions and 0 deletions
25
src/main/java/dev/zontreck/ariaslib/util/FileIO.java
Normal file
25
src/main/java/dev/zontreck/ariaslib/util/FileIO.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package dev.zontreck.ariaslib.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileIO
|
||||
{
|
||||
|
||||
public static String readFile(String filePath) {
|
||||
try {
|
||||
byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
|
||||
return new String(fileBytes);
|
||||
} catch (IOException e) {
|
||||
return "An error occurred: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
public static void writeFile(String filePath, String newContent) {
|
||||
try {
|
||||
Files.write(Paths.get(filePath), newContent.getBytes());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue