Code refactoring.
This commit is contained in:
parent
de18e4bd9f
commit
492e461307
|
|
@ -25,21 +25,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
public class FileOperations {
|
public class FileOperations {
|
||||||
|
|
||||||
public static boolean writeTextToFile(String filePath, String text) {
|
public static boolean writeTextToFile(String filePath, String text) {
|
||||||
File file = new File(filePath);
|
return writeBytesToFile(filePath, text.getBytes(StandardCharsets.UTF_8));
|
||||||
if (!file.canWrite()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
FileOutputStream fileStream = new FileOutputStream(file);
|
|
||||||
fileStream.write(text.getBytes(StandardCharsets.UTF_8));
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean writeBytesToFile(String filePath, byte[] bytes) {
|
public static boolean writeBytesToFile(String filePath, byte[] bytes) {
|
||||||
|
|
@ -51,10 +37,11 @@ public class FileOperations {
|
||||||
try {
|
try {
|
||||||
FileOutputStream fileStream = new FileOutputStream(file);
|
FileOutputStream fileStream = new FileOutputStream(file);
|
||||||
fileStream.write(bytes);
|
fileStream.write(bytes);
|
||||||
|
return true;
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue