Compare commits

...

3 commits

Author SHA1 Message Date
Filip 492e461307 Code refactoring. 2025-03-15 14:37:46 +01:00
Filip de18e4bd9f Added writeBytesToFile method. 2025-03-15 14:35:26 +01:00
Filip 23c621784c Changed source and target to release property. 2025-03-15 14:33:45 +01:00
2 changed files with 9 additions and 5 deletions

View file

@ -14,8 +14,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release>
</properties>
<dependencies>

View file

@ -25,6 +25,10 @@ import java.nio.charset.StandardCharsets;
public class FileOperations {
public static boolean writeTextToFile(String filePath, String text) {
return writeBytesToFile(filePath, text.getBytes(StandardCharsets.UTF_8));
}
public static boolean writeBytesToFile(String filePath, byte[] bytes) {
File file = new File(filePath);
if (!file.canWrite()) {
return false;
@ -32,11 +36,12 @@ public class FileOperations {
try {
FileOutputStream fileStream = new FileOutputStream(file);
fileStream.write(text.getBytes(StandardCharsets.UTF_8));
fileStream.write(bytes);
return true;
} catch (FileNotFoundException ex) {
return false;
} catch (IOException ex) {
return false;
}
return false;