본문 바로가기

전체 글158

자바 파일 인코딩 알아내기 FileReader 같은 곳의 getEncoding 은 시스템의 기본 charset 밖엔 리턴하지 않는다. 실제 파일의 정확한 인코딩을 알아내기 위해서 http://glaforge.free.fr/wiki/index.php?wiki=GuessEncoding 위 라이브러리를 사용해봤다. public static String getFileEncoding(String fullPath) throws IOException { File file = new File(fullPath); Charset charset = CharsetToolkit.guessEncoding(file, 4096); return charset.toString(); } 이런 형식으로 사용하면 된다. [출처] 자바 파일 인코딩 알아내기|작성자 건호랩 2010. 4. 15.
자바 인코딩 관련 =============================== 인코딩 확인 =============================== 3가지가 있다.. 1) String enc = new java.io.OutputStreamWriter(System.out).getEncoding(); System.out.println("default encoding = " + enc); 2) FileReader fr = new FileReader("C:/test"); System.out.println("FileReader.getEncoding()====>"+fr.getEncoding()); 3) System.out.println("file.encoding =" + System.getProperty("file.encoding")).. 2010. 4. 15.
자바 텍스트 파일 이어쓰기 public class UsingFile { public UsingFile() { } public static void main(String[] args) { try { String name = "c:\\tmpfile.txt"; RandomAccessFile raf = new RandomAccessFile(name, "rw"); raf.seek(raf.length()); raf.writeBytes("\r\n " + new String(message.getBytes("KSC5601"), "8859_1")); } catch (IOException e) { System.out.println("Error opening file: " + e); } } } 붉은 글씨 : 한글처리 출처 : http://kin.nav.. 2010. 4. 15.
자바 csv 파일 생성2 //import necessary JDBC drivers import java.sql.*; import java.util.*; import java.io.*; public class csvTest2 { private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); public static void main(String args[]) throws IOException { String url = "jdbc:mysql://localhost:3306/"; //MySQL URL String dbName = ""; //Declare Database Name variable String usr = ""; //Decl.. 2010. 4. 15.