1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-13 08:30:39 +02:00

FileUtils:copyStringToFile: Try not to leak file.

This commit is contained in:
Ganblejs 2024-03-11 22:05:06 +01:00 committed by José Rebelo
parent 8907757674
commit 758e9223d1

View File

@ -97,15 +97,16 @@ public class FileUtils {
* @param dst the file to write to
* @throws IOException
*/
public static void copyStringToFile(String string, File dst, String mode) throws IOException{
BufferedWriter writer;
if (Objects.equals(mode, "append")) {
writer = new BufferedWriter(new FileWriter(dst, true));
} else {
writer = new BufferedWriter(new FileWriter(dst, false));
}
writer.write(string);
writer.close();
public static void copyStringToFile(String string, File dst, String mode) throws IOException {
boolean append = true;
if (!Objects.equals(mode, "append")) append = false;
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(dst, append));
writer.write(string);
writer.close();
} catch (IOException e) {
throw e;
};
}
/**