2 Replies Latest reply: Feb 1, 2008 8:11 AM by 807601 RSS

    reading and updating text file

    807601
      I am new to Java, developing for only one month.

      I need to read a wordperfect file and replace all left tabs within the file with a generic code and write the result to another text file.

      I am able to read the input file, but when I display the string, it does not contain the left tab. I can open the file through notepad and view, search and find the left tab, but it cannot find the left tab when I display the line.

      My code is as follows :

      public static void WriteFile(String[] iFile){
      try{
      // Open the file that is the first
      // command line parameter
      FileInputStream fstream = new FileInputStream(iFile[0]);
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));

      String strLine;
      // ****
      FileWriter out = new FileWriter("testWrite.txt");
      // ****
      //Read File Line By Line

      while ((strLine = br.readLine()) != null) {
      // Print the content on the console
      int lne;
      lne = 0;
      for (int cnt=0; (cnt < 6 && strLine.trim().length() > cnt) ; cnt++, ++lne){
      System.out.println ("First 5 Characters " + "lne is " + lne + " "+ strLine.charAt(cnt));
      }
      System.out.println (strLine);
      strLine.replaceAll("", "#I21");
      out.write(strLine);
      }
      //Close the input stream
      in.close();
      out.flush();
      out.close();
      } catch (Exception e){//Catch exception if any
      System.out.println("Error: " + e.getMessage());
      }
      }
      }