3 Replies Latest reply: Sep 17, 2007 12:56 AM by 807605 RSS

    problem with PrintWriter class


      I am using following prog. for reading and writting to and from a Chinese file.

      package newPackage;

      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.io.OutputStreamWriter;
      import java.io.PrintWriter;
      import java.io.UnsupportedEncodingException;

      public class ReadNWriteChinese {

           static String FILE_NAME = "testFile.txt";

           static String FILE_ENCODING = "UTF-8";

           static String CHINESE_FILE = "ChineseText.txt";

           public static void main(String[] args) {

                PrintWriter out = null;
                BufferedReader bReader = null;
                try {
                     out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(
                               new File(FILE_NAME)), FILE_ENCODING));
                     bReader = new BufferedReader(new InputStreamReader(
                               new FileInputStream(CHINESE_FILE), FILE_ENCODING));

                     String line = null;

                     while ((line = bReader.readLine()) != null) {
                          System.out.println("--------String to write is :: " + line);


                } catch (UnsupportedEncodingException e) {
                     // TODO Auto-generated catch block
                } catch (FileNotFoundException e) {
                     // TODO Auto-generated catch block
                } catch (IOException e) {
                     // TODO Auto-generated catch block
                } finally {


      While testing of the application we have a senario where we are trying to write a file to say "Floppy Drive" which is full.
      But in my case it's not throwing IOException when I am wrtting a Chinese text file (in UTF-8 encoding) to a floppy drive which is full.
      Earlier for wrtting simple English text I was using simply FileWriter class. And it was properly throwing IOException.

      Please guide me how to handle this situation.