内のテキストを書く私は、CSVファイルを読み込むコード内のテキストを編集し、.txtファイルに戻ってそれを記述しようとしています次のコード読むと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);
}
}
を見てください。私の問題はポルトガル語なので、ファイルはANSI
の形式で読み書きする必要があります。現在、いくつかのポルトガル語が出力ファイルのシンボルに置き換えられています。
テキストデータをJavaでANSI形式のファイルに読み書きするにはどうすればよいですか?
リスト farmacias = Files.readAllLines(Paths.get( "c:\\ tmp \\ Farmacias.txt")、Charset.forName( "Cp1252")); –
私は同意しない> Windows用の適切なJavaエンコードANSIはCp1252ですANSIはマイクロソフトのトリックであり、設定できるエンコードの種類は異なります。 Windowsの設定に応じて、GBK、Shift_JISなどにすることもできます。 – TKJohn