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