Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to Read a Portion of a File in Java?

  1. #1
    Member
    Join Date
    May 2008
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default How to Read a Portion of a File in Java?

    Hi folks,

    Output Should be:

    Date Bill Bill DateDescript Frm To Dist pur Qty @ Amt Rmk

    01/02/08 256 01/02/08 Ring Hyd Bng 100 xyz 100 abcd 100 top
    02/05/08 325 05/02/08 paper Chnn Bng 25 offi 850 kir 1000 good
    11/05/08 898 21/08/08 pen Hyd Pun 2532 Offi 200 Abv 500 Bad
    11/02/08 998 21/08/08 Pencil Mum Bng 258 Off 205 Acc 600 Good
    02/05/08 968 30/08/08 Bag Hyd Bng 265 Xyz 536 Acc 635 Bad
    Attached Files Attached Files
    Last edited by jazz2k8; May 19th, 2008 at 05:11 AM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 289 Times in 225 Posts
    Blog Entries
    4

    Default Re: How to Read a Portion of a File

    Hey jazz2k8,

    I would suggest using Regular expressions to do this.

    This should get you started:

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Expense {
     
     public static String inputFile = "expense.txt";
     
     public void formatFile() {
     
      try
      {
      FileInputStream in = new FileInputStream(inputFile);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
     
      String regEx1 = "([0-9]/)"; 
      Pattern regEx1P = Pattern.compile(regEx1);
     
      System.out.println("Date     " + "Bill   " + "BillDate " + "Descript" + " Frm   " +
        "To  " + "Dist   " + "pur   " + "Qty " + " @  " + "Amt    " + "Rmk");
     
      while((strLine = br.readLine())!= null)
      {   
       Matcher match1 = regEx1P.matcher(strLine);
     
       if (match1.find())
       {
        System.out.println(strLine);
       }
     
       //System.out.println(strLine);
      }
      }
      catch (Exception e)
      {
       System.out.println("Ouch! " + e);
      }
     }
     
     public static void main(String[] args) {
      Expense exp = new Expense();
      exp.formatFile();
     
     }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Member
    Join Date
    May 2008
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How to Read a Portion of a File

    Thanks alot PF.....

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Location
    SomeWhere in the world
    Posts
    27
    Thanks
    1
    Thanked 11 Times in 6 Posts

    Default Re: How to Read a Portion of a File

    Please PF if you make comments for this sample.
    Thanks for your help

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Achat Imipramine tablette pharmacie, acheter Tofranil 75mg pharmacie a bon compte france

    Acheter Tofranil === PHARMACIE EN LIGNE === Achat Imipramine
    Please click below.
















    sans ordonnance Imipramine en ligne afin Courbevoie Bourges
    acheter Imipramine generique diovan hct La Roche-sur-Yon
    sans ordonnance Imipramine pharmacie au rabais nouveau brunswick
    acheter Tofranil bon marche prix Quebec
    generique Imipramine 75 mg pharmacie gratuit tablette pour
    achat Imipramine prescrire united nations medicament
    achat Tofranil Kitchener
    sans ordonnance Imipramine Meaux
    sans ordonnance Tofranil 75 mg prescrire eu medicament
    achat Imipramine en ligne afin
    generique Tofranil en ligne
    acheter Tofranil ligne a bon franche comte
    Achat Ezetimibe en ligne, achat Zetia 10 mg en france - Blogs - PaPel.gr
    achat Imipramine 25mg ordonnance pilule
    sans ordonnance Imipramine en ligne Fort-de-France
    sans ordonnance Tofranil france prix
    achat Imipramine medicament generique
    sans ordonnance Tofranil vendre acheter Ajaccio
    achat Imipramine pharmacie nist prescrire
    generique Tofranil pharmacie a paris
    Mayhem Forum
    sans ordonnance Imipramine pharmacie au rabais pour
    achat Tofranil pharmacie en ligne en france cheveux
    acheter Imipramine tablette pharmacie
    achat Imipramine pilule nist prescrire Beauvais
    achat Tofranil sans prescrire pilule contraceptive Windsor Kelowna
    acheter Tofranil comprime pharmacie ordonnance
    generique Imipramine pharmacie en ligne en france achat
    acheter Tofranil 75 mg gracieux ordonnance
    achat Tofranil comprime pharmacie vallee d aoste Asnieres-sur-Seine
    achat Tofranil pharmacie au rabais nouveau brunswick
    achat Tofranil pharmacie en ligne en france achat
    generique Tofranil pharmacie livrer a domicile de medicaments
    acheter Tofranil 75mg pilule du lendemain
    achat Tofranil ordonnance pilule
    achat Tofranil en montreal
    generique Tofranil bon marche prix
    http://www.impulseengineeringgroup.c...steltmepurger/
    sans ordonnance Tofranil pharmacie a bon compte france Ottawa
    generique Tofranil sens prescrire Kamloops
    achat Tofranil pharmacie au rabais pour
    acheter Tofranil comprime pharmacie vallee d aoste
    sans ordonnance Tofranil pharmacie au rabais comtat venaissin Beauvais
    achat Tofranil 25 mg pharmacie gratuit tablette pour
    generique Tofranil pilule du lendemain
    generique Imipramine envoyer buy online Markham
    sans ordonnance Imipramine Nova Scotia
    Acheter Buspar en france, achat Buspirone 10mg en paris - Blogs - ^-^|| w.W.w.3A1IT.CoM || ^-^
    achat Tofranil pharmacie au rabais comtat venaissin Toronto
    sans ordonnance Imipramine pharmacie a bon compte france Saint-Pierre
    generique Tofranil pharmacie au rabais pour
    generique Imipramine Outaouais
    sans ordonnance Imipramine pharmacie vente acheter
    acheter Imipramine Vitry-sur-Seine
    achat Imipramine pharmacie en ligne en suisse generique Frejus
    generique Tofranil acheter bon marche
    acheter Imipramine pilule nist prescrire
    acheter Imipramine sans ordonnance Niort
    achat Tofranil 75mg distribuer ses
    sans ordonnance Tofranil beon pharmacie Limoges

Similar Threads

  1. Java program to read last line of a file
    By JavaPF in forum File Input/Output Tutorials
    Replies: 2
    Last Post: September 10th, 2009, 02:26 AM
  2. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  3. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM