Created writeTextToFile method.

This commit is contained in:
Filip 2025-03-15 00:39:22 +01:00
parent 830560a65d
commit bb8713049b

View file

@ -0,0 +1,44 @@
/*
This file is part of Proculite common.
Proculite common is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
Proculite common is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Proculite common. If not, see <https://www.gnu.org/licenses/>.
*/
package com.proculite;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
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;
}
}