I'm trying to write text to file.
If I use file = "C:\Temp\Dir\Test.txt", then I have no problem
If I use file with cyrillic in path = "C:\Temp\Папка на русском\Test.txt", then I have exception
Note. directories aren't created before code running
public Boolean writeStringToFile(String content, File file) {
status = false;
try (FileOutputStream fos = new FileOutputStream(file, false);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
BufferedWriter fileWriter = new BufferedWriter(osw)) {
fileWriter.write(content);
status = true;
} catch (FileNotFoundException e) {
logger.error("File {}/{} can not be created.", file.getPath(), file.getName(), e);
}
return status;
}
for testing:
writeStringToFile("writeStringToFile is ok. Кодировка UTF-8",
new File(Files.temporaryFolderPath() + "Папка на русском" + File.separator + "Test.txt"))
assertTrue(file.exists());