J'écris un fichier csv que j'ai également besoin de compresser, et j'utilise java.util.zip.ZipEntry et java.util.zip.ZipOutputStream.Écrire des caractères coréens dans un fichier .csv compressé en Java
Tout fonctionne très bien quand j'ai des caractères occidentaux dans toutes les colonnes, mais quand j'utilise des caractères coréens, il ne reconnait pas le/n et tout semble foiré et sur la même ligne. Je l'écris en caractères UTF-8, et je m'attends à ce que ça couvre le coréen.
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class CreateCSV {
public static void main(String[] args) throws IOException {
DateTime utcDateTime = new DateTime().toDateTime(DateTimeZone.UTC);
DateTime newDateTime = utcDateTime.toDateTime();
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyyMMdd-HHmmss-SSS-");
File zipFile = new File("C:/TestCSVKorean/"+ dateFormatter.print(newDateTime) + "Export.zip");
FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
// Open up the zipfile and create the csv entry
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fileOutputStream));
zos.putNextEntry(new ZipEntry(dateFormatter.print(newDateTime) + "tics.csv"));
// The first line of the CSV is a header line
StringBuffer csvHeader = new StringBuffer(
"Time,Name,Rev,Appme,EnvName,PlanName,PlanRev,"
+ "Og Name,Op Name,"
+ "TTR,Lat,Bys Rec,Bytt,"
+ "RPl,Request Method,URI Path,Query String,HTTP Status Code,"
+ "HTTP Request Headers,User Agent,Request Body,HTTP Response Headers,Response Body\n");
zos.write(csvHeader.toString().getBytes(), 0, csvHeader.length());
StringBuffer csvData = new StringBuffer("");
csvData.append("\"" + newDateTime + "\",\"" +
"apiName" + "\"," +
"2.0.0" + ",\"" +
"app name" + "\",\"" +
"env name" + "\",\"" +
"plan name" + "\"," +
"2" + ",\"" +
"dev org name" + "\",\"" +
"ìº˜ë¦°ë” ëª©ë¡ì¡°íšŒ(ë‚´ 캘린ë”, 구ë…가능한 캘린ë”, 시스템 캘린ë”, ê´€ë¦¬ìž ìº˜ë¦°ë”)" + "\"," +
"123" + "," +
"inifd: 334;dshs: 343" + ", " +
"10" + "," +
"33" + ",\"" +
"http" + "\",\"" +
"GET" + "\",\"" +
"/dsfs/sdf/ds" + "\",\"" + "query string" + "\",\"" +
"200" + "\",\"" +
"jshkshdf" + "\",\"" +
"sdjhfks/sdfs/" + "\",\"" +
"jhksdfhks dsfs" + "\",\"" +
"dsfsdfs" + "\",\"" +
"dsfsfs" + "\"\n");
zos.write(csvData.toString().getBytes("UTF-8"), 0, csvData.length());
csvData = new StringBuffer("");
csvData.append("\"" + newDateTime + "\",\"" +
"apiName" + "\"," +
"2.0.0" + ",\"" +
"app name" + "\",\"" +
"env name" + "\",\"" +
"plan name" + "\"," +
"2" + ",\"" +
"dev org name" + "\",\"" +
"ìº˜ë¦°ë” ëª©ë¡ì¡°íšŒ(ë‚´ 캘린ë”, 구ë…가능한 캘린ë”, 시스템 캘린ë”, ê´€ë¦¬ìž ìº˜ë¦°ë”)" + "\"," +
"123" + "," +
"inifd: 334;dshs: 343" + ", " +
"10" + "," +
"33" + ",\"" +
"http" + "\",\"" +
"GET" + "\",\"" +
"/dsfs/sdf/ds" + "\",\"" + "query string" + "\",\"" +
"200" + "\",\"" +
"jshkshdf" + "\",\"" +
"sdjhfks/sdfs/" + "\",\"" +
"jhksdfhks dsfs" + "\",\"" +
"dsfsdfs" + "\",\"" +
"dsfsfs" + "\"\n");
zos.write(csvData.toString().getBytes("UTF-8"), 0, csvData.length());
zos.close();
}
}
C'est ce que je vois quand j'ouvre le fichier csv:
Nom Temps Rev Appme envname PlanName PlanRev Og Nom Op Nom TTR Lat Bys Rec Bytt RPL Demande Méthode URI Chemin de requête Chaîne HTTP Code d'état HTTP En-tête de requête Agent utilisateur Corps de la requête HTTP En-tête de réponse Corps de la réponse
2016-01-28T17: 20: 56.859Z apiName 2.0.0 nom de l'application env name nom du plan 2 dev org nom 캘à °  ° ° «Â ª ª ° (((((((((((((((((€, à € à € à € à € à € à € à € à € à € à € à € à € |Å "ì ° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° que 123 343 10 33 http 2016-01-28T17: 20: 56.859Z apiName 2.0.0 nom de l'application env nom nom du plan 2 dev nom de l'organisation 캘à° Ã⠀ šÃƒÂ © Ãà ¡Â °  (à € à € à € à € à € à € à € à € à € à € à € à € ì ° ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà [rÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃrà ... |¬ìž ìº˜à «Â| ° ë AA €) 123: 334; inifd DSHS: 343 10 33 http
Il est collé le champ de date à partir de la deuxième rangée en t Il demande le champ de méthode du premier: 2016-01-28T17: 20: 56.859Z
Votre fichier CSV semble correct. Le problème est dans la façon dont vous le voyez. Quel programme utilisez-vous pour l'ouvrir? – VGR