2013-06-03 2 views
1

일본어 텍스트를 읽을 수있는 텍스트로 변환하는 데 문제가 있습니다. 지금은 사용자로부터 가치를 얻는 평가판 프로그램이 있습니다. 그런 다음이 값은 단어를 호출하여 객체를 만드는 클래스를 통해 전달됩니다. 일단 객체가 생성되면 객체를 작성하여 파일에 읽고 싶습니다. 필자는 객체를 읽고 쓰고 있기 때문에 이것을하기 위해 객체 출력과 입력 스트림을 사용하고 있습니다. 이 문제는 objectoutput 및 입력 스트림을 사용하는 동안 UTF-8 사용중인 파일을 인코딩하는 방법을 잘 모르겠다는 것입니다. 인코딩을 사용하지 않으면 가나 나 한자가 있어야하는 곳에 물음표가 표시됩니다.유니 코드의 일본어 텍스트

어쨌든 objectoutput 또는 입력 스트림을 사용하여 파일을 유니 코드로 변환 할 수 있습니까? 그렇지 않다면 가나 나 한자가 있어야하는 물음표를 피할 수있는 다른 방법이 있습니까?

public class JavaApplication1 { 

    /** 
    * @param args the command line arguments 
    */ 

    Scanner scan = new Scanner(System.in); 

    public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException, FontFormatException { 
     // TODO code application logic here 
     JavaApplication1 ja = new JavaApplication1(); 
     ja.start(); 
    } 
    public void start() throws FileNotFoundException, IOException, ClassNotFoundException, FontFormatException{ 

     System.out.println("Enter Kanji"); 
     String Kanji = scan.next(); 
     System.out.println("Enter Romanji"); 
     String Romanji = scan.next(); 
     System.out.println("How common is it"); 
     int common = scan.nextInt(); 
     System.out.println("How many types of word is it?"); 
     int loop = scan.nextInt(); 
     ArrayList type = new ArrayList(); 
     for(int i = 0; i<loop;i++){ 
      System.out.println("What type of word"); 
      type.add(scan.nextInt()); 
     } 
     System.out.println("What type of adjective"); 
     int adjective = scan.nextInt(); 
     System.out.println("What type of verb"); 
     int verb = scan.nextInt(); 
     System.out.println("How many radicals"); 
     int loop2 = scan.nextInt(); 
     ArrayList radical = new ArrayList(); 
     for(int i = 0; i<loop2;i++){ 
      System.out.println("radical"); 
      radical.add(scan.nextInt()); 
     } 
     //String newKanji = GetUnicode(Kanji); 
     Word word = new Word(Kanji,Romanji,common,type,adjective,verb,radical); 
     word.getKanaKanji(); 
     store(word); 
     //store(word); 
     read(); 

    } 
    public void store(Word word) throws FileNotFoundException, IOException, FontFormatException{ 
     File file = new File("test.dat"); 
     FileOutputStream outFileStream = new FileOutputStream(file); 
     ObjectOutputStream oos = new ObjectOutputStream(outFileStream); 
     oos.writeObject(word); 
     oos.close(); 
    } 
    public void read() throws FileNotFoundException, IOException, ClassNotFoundException, FontFormatException{ 
     File file = new File("test.dat"); 
     FileInputStream filein = new FileInputStream(file); 
     ObjectInputStream ois = new ObjectInputStream(filein); 
     Word word = (Word) ois.readObject(); 
     ois.close(); 
     System.out.println(word.getKanaKanji());//this gets the kanakanji 

    } 
} 

내가 Word 클래스 getKanaKanji 메서드를 호출 할 때 물음표가 나타납니다.

일본어 문자를 지원하는 OS가 있으므로 문제가되지 않습니다.

미리 감사드립니다.

+1

나는 정말로 그것을 얻지 못합니다. 파일에 Object를 쓰면 이진 파일이어야하고 "문자열 인코딩"이 전혀 없습니다. 텍스트 파일을 작성하는 경우 인코딩 문제가 적용됩니다. 물음표는 종종 * font *에 원하는 문자가 없다는 힌트입니다. 그걸 확인 했니? 아마도 유니 코드 코드 포인트 모두를 지원하는 글꼴을 사용해야 할 것입니다. – Fildor

+0

나는 Fildor에 동의하는 경향이 있습니다. 문자 인코딩이 사용되는 곳은 어디에도 없습니다. 이는 아마도 콘솔 응용 프로그램의 문제 일 것입니다. – Aurand

+1

쉬운 테스트는 디스크에 쓰기 전과 후에 콘솔에 개체를 인쇄하는 것입니다. 그것은 바뀌 었습니까? – Aurand

답변

관련 문제