Results 1 to 7 of 7
  1. #1
    mirage_87 is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default how to write onto a file

    hi,
    i m trying to write onto a file.Some of my text is in english and some in urdu.The problem that i m facing is i m able to write the english part correctly but not the urdu part.Here's my code..........



    //urdu_synset contains the urdu string
    //string1,string2,etc are english strings

    fw=new FileWriter("news.txt",true);
    fw.write(" \n" + "\n" + "ID :: " + string1 + "\n");
    fw.write("CAT :: " + string2 + "\n");
    fw.write("CONCEPT :: " + string3 + "\n");
    fw.write("EXAMPLE :: " + string4 + "\n");
    fw.write("SYNSET-URDU :: ");
    fw.close();
    fos=new FileOutputStream("news.txt",true);
    osw=new OutputStreamWriter(fos,"Unicode");
    osw.write(urdu_synset);
    osw.flush();


    i tried writin the urdu string into a different file using OutputStreamWriter in "unicode" format and it worked fine.....but it 's not workin out here....the string comes out to be garbled...........................

    please suggest any suitable solution to my problem.....

  2. #2
    dhnsekaran is offline Member
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Default

    Am Also Having Like The Poblem

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mirage_87 View Post
    i tried writin the urdu string into a different file using OutputStreamWriter in "unicode" format and it worked fine.....but it 's not workin out here....the string comes out to be garbled...........................
    What you working not here? Are you talking about the same file?

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Use BufferedWriter.
    I die a little on the inside...
    Every time I get shot.

  5. #5
    andy_man's Avatar
    andy_man is offline Member
    Join Date
    Oct 2008
    Location
    Yerevan
    Posts
    14
    Rep Power
    0

    Default

    Hi,

    this works for me for different languages started from Russian ended with Cantonese.

    Java Code:
    String fileName = "......";
    OutputStream fout = new FileOutputStream(fileName);
    OutputStream bout = new BufferedOutputStream(fout);
    OutputStreamWriter fwr = new OutputStreamWriter(bout,"UTF-8");
    TEAM = Together Everyone Achieves More :)

  6. #6
    phoenix123 is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Default

    refer examples on java2examples.com

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    if I'm not mistaken, special unicode characters have to be written out using their actual unicode i.e. \u00F6. Code Charts - Scripts has lists of all unicode characters, google helps too :D

Similar Threads

  1. how do i write to a text file from an arraylist?
    By otoro_java in forum New To Java
    Replies: 3
    Last Post: 01-30-2008, 07:53 AM
  2. File Write Error
    By vikain in forum Advanced Java
    Replies: 5
    Last Post: 01-02-2008, 05:38 AM
  3. Write unicode into file
    By vata2999 in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 04:04 PM
  4. Help with write file in java
    By mathias in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:51 PM
  5. Replies: 1
    Last Post: 07-24-2007, 03:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •