Results 1 to 1 of 1
  1. #1
    waelyafooz is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default I can not remove space or tab from text file

    Hi All,
    please advise me why the following code not remove the spaces or tab from the text file.


    Java Code:
        try
        {
            FileReader fr = new FileReader("D:\\Test\\a.txt");
    BufferedReader br = new BufferedReader(fr);
    
    Pattern p;
      Matcher m;
    String line;
     String afterReplace = "";
      String inputText = "";
    while((line = br.readLine()) != null)
    {
       inputText = line;
      p = Pattern.compile("\\s+|\t");
      m = p.matcher(inputText);
      System.out.println(afterReplace);
      afterReplace = afterReplace + m.replaceAll(" ") + "\r\n";
    }
    
      System.out.println(afterReplace);
    fr.close();
    
        }
          catch (Exception e){
      System.err.println("Error: " + e.getMessage());
      }
    my regards
    Wael


    this is the file

    <!--http://videos.kansascity.com/vmix_hosted_apps/p/media?id=4999903 -->
    <![CDATA[<body>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         <br>                                                                                                         Raw Video: Fans  Turn Out to Honor McNair                                  Fans turned out by the thousands for a thre e-hour visitation of slain ex-NFL quarterback Steve McNair.  McNair was shot and  killed last weekend in what police say was a murd er-suicide.  (July 9)                      Nation / World                          By:  AP                                   Comments: text ( 0 ) |  vid eo ( 0 )    + Add a comment              Be the fi rst to  add a comment .                                                                   1           2          3          4          5                  Your Rating               <br>                                                                                                                                                                                                                                                                                                                 Popularity                                                                                                                                       Your Name:                Yo ur Comment:                                                                                                    http://videos.kansascity.com/vmix_hosted_apps/p/media?id=4999903&amp;item_index=&amp;genre_id=0000 0840                                                                   Your Email:                                      Friend's Email:                                      Your Message:                                                                                                                                                                                                                               Top Videos                                        Nation / World                                       Sport s                                       Entertainm ent                                       Business                                        Lifestyle                                        Archive                                        User Submitted                                        Politics                                        Ink                                        Local                                        Selects                                                                                                                      all                         Sort By:                  Most  Recent        Most Popular             Highest Rat ed                                                                  Loading...                                  <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          All users : If you have  not already done so, Click "Record a Comment" to b egin. Next, click "Allow" to use your camera.<br>< br>   Additional Info for Mac users : If you do no t see video (after clicking 'allow'), do the follo wing:<br>      Click on the blue "gear" icon   in  the lower right corner to bring up the settings wi ndow.     Click on the webcam icon.       If you a re using a built in iSight camera, choose USB Vide o Class Video from the pulldown menu. You should s ee video immediately.<br><br>       Click "close"  button.   Record! You must record at least ten sec onds before you can stop.                <br><br>          &nbsp;             </body>]]>
    Last edited by waelyafooz; 11-18-2012 at 09:04 AM.

Similar Threads

  1. how can i remove a line from an ordinary text file?
    By jayeshsugunan in forum New To Java
    Replies: 2
    Last Post: 08-11-2010, 10:05 AM
  2. Remove a Blank Line from Text file
    By nitinverma in forum CLDC and MIDP
    Replies: 8
    Last Post: 06-15-2010, 06:12 AM
  3. [SOLVED] remove all white space from text file
    By loki in forum New To Java
    Replies: 10
    Last Post: 04-26-2009, 11:52 AM
  4. remove variables/line in a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-04-2009, 03:05 AM
  5. How to remove 2 last lines in a text file?
    By Marius in forum New To Java
    Replies: 2
    Last Post: 11-30-2008, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •