Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8270259

Error in FileIO Operation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 16
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE PROBLEM :
      FileInputStream doesn't Write

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.FileWriter;
      import java.io.IOException;


      public class FileExist {

      public static void main(String[] args) {
      File a = new File("E:\\Sampletext1.txt");
      if (a.exists()) {
      throw new FileAlreadyExistException();
      } else {
      FileWriter c = null;
      FileInputStream d = null;
      FileOutputStream e = null;
      try {
      a.createNewFile();
      c = new FileWriter("E:\\Sampletext1.txt");
      c.write("Hello World!");

      d = new FileInputStream("E:\\Sampletext1.txt");
      e = new FileOutputStream("E:\\Sampletext2.txt");

      int f = 0;

      while ((f = d.read()) != -1) {
      e.write(f);
      System.out.println("file IO success");
      }
      } catch (IOException g) {
      g.printStackTrace();

      } finally {
      try {
      c.close();
      d.close();
      e.close();
      } catch (IOException g) {
      g.printStackTrace();
      }
      }
      }

      }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Hello World! to be written in Sampletext2.txt
      ACTUAL -
      Sampletext2.txt is a blank file

        Attachments

          Activity

            People

            Assignee:
            tongwan Andrew Wang
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: