I would like to know how to write a file in ISO-8859-1
and not lose the graphical accent if possible, my doubts come from the following. When defining in Eclipse that the file encoding follows this charset I quoted above, it correctly saves the files using accent but if I were using Java code try to perform a file edit and save in this charset, I will lose the accents. What to do?
public class Diretorio {
public static void main(String[] args) {
Properties properties = new Properties();
InputStream inputStream;
try {
List<File> listFile = getFileList("C:\Users\Diego Macario\Documents\Eclipse\ecred_manat\WebContent");
inputStream = new FileInputStream("c:\teste.properties");
properties.load(inputStream);
for (File file : listFile) {
List<String> lines = Files.readAllLines(file.toPath(), Charset.forName("ISO-8859-1"));
for (Entry<Object, Object> label : properties.entrySet()) {
String key = "#{lbl['" + (String) label.getKey() + "']}";
for (String string : lines) {
if (string.contains(key)) {
int index = lines.indexOf(string);
String value = (String) label.getValue();
value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
string = string.replace(key, value);
lines.set(index, string);
}
}
}
Files.write(file.toPath(), lines, Charset.forName("ISO-8859-1"), StandardOpenOption.TRUNCATE_EXISTING);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static List<File> getFileList(String path) {
String[] extension = { "xhtml" };
List<File> listFile = new ArrayList<>(FileUtils.listFiles(
new File(path), extension, true));
return listFile;
}
}