내가, csv 파일을 읽어 코드의 텍스트를 편집하려고 다음 코드읽기 및 쓰기 텍스트
/*
* 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);
}
}
에서 봐, 다시이 .txt 파일에 기록하십시오. 내 문제는 포르투갈어 단어이므로 파일은 ANSI
형식으로 읽고 쓸 수 있어야합니다. 현재 일부 포르투갈 단어는 출력 파일의 기호로 대체됩니다.
Java에서 텍스트 데이터를 ANSI 형식의 파일로 읽고 쓸 수 있습니까?
목록 farmacias = Files.readAllLines (Paths.get ("c : \\ tmp \\ Farmacias.txt"), Charset.forName ("Cp1252")); –
동의하지 않음> Windows 용 ANSI의 올바른 인코딩은 Cp1252입니다. ANSI는 Microsoft의 트릭이며 다양한 인코딩으로 설정할 수 있습니다. Windows의 설정에 따라 GBK, Shift_JIS 등이 될 수도 있습니다. – TKJohn