import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
public class AnsiToUTF8 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
if(args.length != 1)
{
throw new Exception();
}
String strFileName = args[0];
String[] strs = strFileName.split("\\.");
String[] ssss = strs[0].split("/");
String strFilePriName = ssss[ssss.length - 1];
File tempFile = File.createTempFile(strFilePriName, ".csv");
System.out.println(tempFile.getAbsolutePath());
File sourceFile = new File(strFileName);
FileInputStream fi = new FileInputStream(sourceFile);
InputStreamReader isr = new InputStreamReader(fi,Charset.forName("EUC-KR"));
BufferedReader br = new BufferedReader(isr);
String data = null;
while((data = br.readLine())!=null)
{
System.out.println(data);
appendUTFFile(tempFile.getAbsolutePath(), data);
}
fi.close();
isr.close();
br.close();
sourceFile.delete();
sourceFile.createNewFile();
FileUtils.copyFile(tempFile, sourceFile);
FileUtils.deleteQuietly(tempFile);
}
public static void appendUTFFile(String filename, String content) throws Exception {
BufferedWriter writer;
OutputStream out = new FileOutputStream(filename, true);
writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(content + "\r\n");
writer.close();
}
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
public class AnsiToUTF8 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
if(args.length != 1)
{
throw new Exception();
}
String strFileName = args[0];
String[] strs = strFileName.split("\\.");
String[] ssss = strs[0].split("/");
String strFilePriName = ssss[ssss.length - 1];
File tempFile = File.createTempFile(strFilePriName, ".csv");
System.out.println(tempFile.getAbsolutePath());
File sourceFile = new File(strFileName);
FileInputStream fi = new FileInputStream(sourceFile);
InputStreamReader isr = new InputStreamReader(fi,Charset.forName("EUC-KR"));
BufferedReader br = new BufferedReader(isr);
String data = null;
while((data = br.readLine())!=null)
{
System.out.println(data);
appendUTFFile(tempFile.getAbsolutePath(), data);
}
fi.close();
isr.close();
br.close();
sourceFile.delete();
sourceFile.createNewFile();
FileUtils.copyFile(tempFile, sourceFile);
FileUtils.deleteQuietly(tempFile);
}
public static void appendUTFFile(String filename, String content) throws Exception {
BufferedWriter writer;
OutputStream out = new FileOutputStream(filename, true);
writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(content + "\r\n");
writer.close();
}
}