Write a file in UTF-8 using FileWriter (Java)?

Posted by user1280970 on Stack Overflow See other posts from Stack Overflow or by user1280970
Published on 2012-03-24T15:39:14Z Indexed on 2012/03/24 17:29 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

I have the following code however, I want it to write as a UTF-8 file to handle foreign characters. Is there a way of doing this, is there some need to have a parameter?

I would really appreciate your help with this. Thanks.

    try 
    {
        BufferedReader reader = new BufferedReader(new FileReader("C:/Users/Jess/My Documents/actresses.list"));
        writer = new BufferedWriter(new FileWriter("C:/Users/Jess/My Documents/actressesFormatted.csv"));
        while( (line = reader.readLine()) != null)
        {
            //If the line starts with a tab then we just want to add a movie
            //using the current actor's name.
            if(line.length() == 0)
                continue;
            else if(line.charAt(0) == '\t')
            {
                readMovieLine2(0, line, surname.toString(), forename.toString());
            }
            //Else we've reached a new actor
            else
            {
                readActorName(line);
            }
        }
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about file-io