Java로 Mac OS X에서 파일이름을 UTF-8로 변환하는 방법?

superkkt의 이미지

안녕하세요.

Java로 파일을 전송하는 프로그램을 만들고 있습니다. 윈도우와 맥을 모두 지원해야해서 전송 전에 파일이름을 Local Charset <--> UTF-8로 변환을 합니다. 그런데 윈도우에서는 변환이 잘 되는데, 맥에서는 잘 안되는것 같습니다. 예를 들어 맥에서 "사용 설명서"라는 폴더를 전송하면 서버에서는 "ㅅ ㅏ ㅇ ㅛ ㅇ ㅅ ㅓ ㄹ ㅁ ㅕ ㅇ ㅅ ㅓ"라고 만들어 지네요.

Charset 변환 코드는 아래와 같이 만들어서 쓰고 있는데 혹시 잘못된 점이 있는지요?

public byte [] convertCharacterSet(String str, String enc){
 
    try{			
        Charset charset = Charset.forName(enc);		
        ByteBuffer byteBuffer = charset.encode(str);		
 
        byte [] pre = byteBuffer.array();
        byte [] result = new byte[byteBuffer.limit()];
 
        System.arraycopy(pre, 0, result, 0, result.length);			
 
        return result;
 
    } catch(Exception e){
        e.printStackTrace();
        return null;
    }
}

위 코드에서 변환된 UTF-8 문자열은 DataOutputStream을 사용해서 byte array로 전송합니다.

wkpark의 이미지

코드는 맞을겁니다.

그런데 Mac에서는 한글이 첫가끝 풀어쓰기라더군요. 글자를 랜더링할때 이것을 정규화해서 음절자모로 변환해서 보여주나봅니다.

온갖 참된 삶은 만남이다 --Martin Buber

hayarobi의 이미지

용어로 쓰자면 다른 플랫폼들은 유니코드가 NFC인데 비해 맥오에서는 NFD방식입니다. 비유하자면 NFC가 완성형 방식이고 NFD는 조합형 방식이라고 보시면 됩니다. 굳이 한글뿐 아니라 유럽쪽 언어의 부가기호 처리에서도 서로 다르게 나오죠.
http://www.icu-project.org/ 에서 이런 코드도 변환하는 라이브러리를 제공하나봅니다.

---------- 시그 *****
저도 세벌식을 씁니다.
M$윈도우즈, 리눅스, 맥 오에스 텐, 맥 오에스 클래식을 모두 엔드유저 수준으로 쓴답니다.
http://psg9.egloos.com

=================
잠못자는 한솔아빠

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.