1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
public class test {
public static void main(String[] args) {
// parseFile("C:/existXml/nl/");
// String tmp = loadFile("c:/existxml/fr/2089-829fr.xml");
// String tmp = loadFile("c:/existxml/test.txt");
String tmp = loadFile("c:/temp/0013-219nl.xml");
saveToFile("c:/temp/0013-219nlUTF.xml", tmp, true);
}
public static String loadFile(String f) {
try {
//InputStreamReader b = new InputStreamReader(new FileInputStream(new File(f)), "UTF-8");
//BufferedReader br = new BufferedReader(b);
BufferedReader br = new BufferedReader(new FileReader(new File(f)));
String result ="";
String line;
while ((line = br.readLine()) != null ) {
result = result + line;
}
return result;
}
catch (Exception ie)
{
ie.printStackTrace();
return null;
}
}
private static void saveToFile(String FileName, String content, boolean isUTF) {
try {
FileOutputStream out = new FileOutputStream(FileName);
OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(out), "UTF-8");
// OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(out));
BufferedWriter w = new BufferedWriter(writer);
System.out.println(content);
if (isUTF)
w.write(content);
else
w.write(content);
w.flush();
w.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager