Proszę spojrzeć na następujący kodOdczyt i zapis tekstu w formacie ANSI
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author
*/
import java.io.*;
public class CSVConverter
{
private File csvFile;
private BufferedReader reader;
private StringBuffer strBuffer;
private BufferedWriter writer;
int startNumber = 0;
private String strString[];
public CSVConverter(String location, int startNumber)
{
csvFile = new File(location);
strBuffer = new StringBuffer("");
this.startNumber = startNumber;
//Read
try
{
reader = new BufferedReader(new FileReader(csvFile));
String line = "";
while((line=reader.readLine())!=null)
{
String[] array = line.split(",");
String inputQuery = "insertQuery["+startNumber+"] = \"insert into WordList_Table ('Engl','Port','EnglishH','PortugueseH','Numbe','NumberOf','NumberOfTime','NumberOfTimesPor')values('"+array[0]+"','"+array[2]+"','"+array[1]+"','"+array[3]+"',0,0,0,0)\"";
strBuffer.append(inputQuery+";"+"\r\n");
startNumber++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println(strBuffer.toString());
//Write
try
{
File file = new File("C:/Users/list.txt");
FileWriter filewrite = new FileWriter(file);
if(!file.exists())
{
file.createNewFile();
}
writer = new BufferedWriter(filewrite);
writer.write(strBuffer.toString());
writer.flush();
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[]args)
{
new CSVConverter("C:/Users/list.csv",90);
}
}
próbuję odczytać pliku csv, edytować tekst w kodzie, a następnie zapisz go z powrotem do pliku .txt. Mój problem polega na tym, że mam portugalskie słowa, więc plik powinien zostać odczytany i zapisany w formacie ANSI
. W tej chwili niektóre portugalskie słowa są zastępowane symbolami w pliku wyjściowym.
Jak mogę odczytać i zapisać dane tekstowe w pliku w formacie ANSI w Javie?
Lista farmacias = Files.readAllLines (Paths.get ("c: \\ tmp \\ Farmacias.txt"), Charset.forName ("Cp1252")); –
Nie zgadzam się na> Prawidłowe kodowanie Java dla Windows ANSI to Cp1252 ANSI jest sztuczką Microsoftu i można ją ustawić na kodowanie zmienne. Może to być również GBK, Shift_JIS i tak dalej, w zależności od ustawienia systemu Windows. – TKJohn