title: How to resolve java.io.IOException: Read error at java.io.FileInputStream.read(Native Method)?
body: <p>I'm getting the following error,  </p>
  
  <pre><code>java.io.IOException: Read error  
  at java.io.FileInputStream.read(Native Method) at      
  com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source) 
  at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity  
  (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion (Unknown Source)
         at    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
  at   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)  
  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)  
  at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)  
  at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
  at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)  
  at com.example.TestIntegrate.execute(TestIntegrate.java:71)  
  at com.example.TestIntegrate.main(TestIntegrate.java:42)  
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>    public class TestIntegrate {
  
      private Document doc = null;
      public static void main(String[] args) {
          FileInputStream fin;
          try {
              fin = new FileInputStream("C:/Users/xyz/workspace/TEST_2.xml");
              FileOutputStream fout = new FileOutputStream("C:/Users/xyz/workspace/OutputFile.xml");      
              TestIntegrate t = new TestIntegrate();
              t.execute(fin, fout);
          } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      public void execute(InputStream sourceFile, OutputStream targetFile) //throws StreamTransformationException
      {       
          BufferedReader reader;
          OutputStreamWriter writer;
          try{    
  
              // creating the parser object 
              DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
              String line = "&lt;Tax&gt;";
              String line1 = "&lt;/Tax&gt;";
              String currentLine;
              reader = new BufferedReader(new InputStreamReader(sourceFile));
              writer =new OutputStreamWriter(targetFile);
  
              dbFactory.setNamespaceAware(true);
              DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
              while ( (currentLine = reader.readLine() ) != null){
                    String trimmedLine = currentLine.trim();
                    if(trimmedLine.equals(line) || trimmedLine.equals(line1) ) continue;
                    writer.write(currentLine + System.getProperty("line.separator"));
              }
              reader.close();
              writer.close();
              doc = dBuilder.parse(sourceFile);
              writeOutputfile(doc,targetFile);   
          } catch (Exception e) { 
              e.printStackTrace();    
          }   
      }
      private void writeOutputfile(Document doc,OutputStream targetFile) { 
              try {
  
                  TransformerFactory transformFactory = TransformerFactory.newInstance();
                  DOMSource source = new DOMSource(doc);
                  Transformer transformer;
                  transformer = transformFactory.newTransformer();
                  Writer outWriter = new StringWriter();   
                  StreamResult result = new StreamResult(targetFile);   
                  transformer.transform(source,result);
              }
                   catch (TransformerException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
              }
      }
  
  }
  </code></pre>
  
  <p>The <strong>process</strong> I have to do is:</p>
  
  <p>1) reading the file from the source location.. ( here I am using main() just for testing purpose)</p>
  
  <p>2) deleting the <code>&lt;Tax&gt;</code> and <code>&lt;/Tax&gt;</code> nodes in the source file.</p>
  
  <p>3) writng the file to target location.  </p>
  
  <p>XML FIle:</p>
  
  <pre><code>&lt;!-- language: lang-xml --&gt;
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;School&gt;
      &lt;SSLC&gt;
          &lt;name /&gt;
          &lt;rollno /&gt;
      &lt;/SSLC&gt;
      &lt;Tax&gt;
          &lt;first_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/first_pu&gt;
          &lt;second_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/second_pu&gt;
      &lt;/Tax&gt;
      &lt;Tax&gt;
          &lt;first_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/first_pu&gt;
          &lt;second_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/second_pu&gt;
      &lt;/Tax&gt;
      &lt;Tax&gt;
          &lt;first_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/first_pu&gt;
          &lt;second_pu&gt;
              &lt;name /&gt;
              &lt;rollno /&gt;
          &lt;/second_pu&gt;
      &lt;/Tax&gt;
  &lt;/School&gt;
  </code></pre>
  
  <p>please tell me the way to resolve this issue..</p>
  
  <p>Thanks in advance.. </p>