0
J'ai une table et dans une colonne nous avons des caractères chinois. J'essaie d'écrire les données dans un fichier .txt en utilisant l'encodage GBK, mais il est brouillé. Si j'utilise UTF8 alors il montre le caractère chinois correct mais, je ne veux pas utiliser UTF8.Comment écrire un caractère chinois dans un fichier texte en utilisant l'encodage GBK?
String url = "jdbc:oracle:thin:@localhost:1521:TEST";
String user = "testUser";
String pwd = "testUser";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(url, user, pwd);
String sql = "Select *from test_table where id=1234";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet resultSet = stmt.executeQuery();
String fileName = "C:\\temp\\aaaa.txt";
try (FileOutputStream os = new FileOutputStream(fileName)) {
PrintWriter pw = null;
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os, "GBK")));
String[] data = new String[5];
String line;
while (resultSet.next()) {
data[0] = resultSet.getString(1);
data[1] = resultSet.getString(2);
data[2] = resultSet.getString(3);
data[3] = resultSet.getString(4);
data[4] = resultSet.getString(5);
line = setLine(data);
System.out.println(line);
pw.print(line);
}
pw.flush();
}
}
private static String setLine(String[] data) {
StringBuilder line = new StringBuilder();
String delim = ",";
int count= data.length;
for (int i = 0; i < count; i++) {
if (i > 0)
line.append(delim);
if (data[i] != null) {
line.append(data[i]);
}
}
return line.toString();
}
Je ne veux pas de fourmi. Ceci est un fichier java simple et de plus l'encodage peut très bien big5 aussi – Arat
Oui ça pourrait être –