HELP - Buffered Reader

Below is a portion of my program, its a simple app, that is supposed to read a policy number, and then display the results. I can't get it to read the file, or output onto the app. Any help would be appreciated.
the file is called loans.txt and a line looks like this...
12322|Smith, Dennis|456 Westfield Blvd|Westfield, IN 46033|$2,500|1/1/2001|7/11/2005|None
public void GetFile(){
//User's entered policy number is stored here
String Policy_Num_Entered = SearchFor.getText();
/*If the the policy is found in loans.txt, sucess will be changed to 1,
otherwise it will stay 0 and be used to output a "I'm Sorry message*/
int sucess = 0;
//Try Catch Block
try{
BufferedReader br = new BufferedReader(new FileReader(file));
//Access the first line of loans.txt
String line = br.readLine();
//Read the # of lines in loans.txt
LineNumberReader read = new LineNumberReader(new FileReader(file));
//Assign the # of lines to count
int count = read.getLineNumber();
//Item being looked by the String Tokenizer
String Item;
//For loop, looping the # of times a line must be read
for(int x = 0; x < count; x++){
//While Line is not empty, proceed
while ( line != null )
//Read individual words of the line from loans.txt
StringTokenizer tokenizer = new StringTokenizer(line, "|");
Item = tokenizer.nextToken();
//While the line has more words
while(tokenizer.hasMoreTokens() )
//If Word equals "The" add 1 tot he sum
if(Item == Policy_Num_Entered){
//Fill in policy Number
Policy_Number.append(Item);
Item = tokenizer.nextToken();
//Fill in First and Last Name
Name.append(Item);
//Item = tokenizer.nextToken();
//Name.append(" " + Item);
Item = tokenizer.nextToken();
//Fill in Address
Address.append(Item);
Item = tokenizer.nextToken();
//Address.append(" " + Item);
//Item = tokenizer.nextToken();
//Address.append(" " + Item);
//Item = tokenizer.nextToken();
//Fill in City, State and Zip Code
City_St_Zip.append(Item);
Item = tokenizer.nextToken();
//City_St_Zip.append(" " + Item);
//Item = tokenizer.nextToken();
//City_St_Zip.append(" " + Item);
//Item = tokenizer.nextToken();
//Fill in Loan Balance
LoanBal.append(Item);
Item = tokenizer.nextToken();
//Fill in Loan Effective Date
LoanEffDate.append(Item);
Item = tokenizer.nextToken();
//Fill in Maturity Date
MatDate.append(Item);
Item = tokenizer.nextToken();
//Take all the words that are left to fill in Notes
//while(tokenizer.hasMoreTokens() ){
Notes.append(" " + Item );
Item = tokenizer.nextToken();
//end of while has more tokens
//Item found so change to 1
sucess = 1;
//Break out of the loop
break;
}//end of If
//Grab the next word
Item = tokenizer.nextToken();
}//end of while tokenizer
}//end of while
//Read the next line
line = br.readLine();
}//for loop
if(sucess == 0)
JOptionPane.showMessageDialog(Finalapp.this, "I'm sorry the Policy " +
Policy_Num_Entered + " was not found. Please try "+
"again.");
//Close the buffered Reader, and close the .dat file
br.close();
}//End of try
//Catch any errors that may have occured in the reader
catch(IOException exception)
exception.printStackTrace();
}//end of catch
}//end of GetFile

Ok I know that my line reader was messing up, so it was never running the loop, my new code reads like this...
public void GetFile(){
//User's entered policy number is stored here
String Policy_Num_Entered = SearchFor.getText();
/*If the the policy is found in loans.txt, sucess will be changed to 1,
otherwise it will stay 0 and be used to output a "I'm Sorry message*/
int sucess = 0;
//Try Catch Block
try{
BufferedReader br = new BufferedReader(new FileReader("loans.txt"));
/*FileInputStream file = new FileInputStream("c:\\loans.txt");
BufferedReader br = new BufferedReader( new InputStreamReader( file) );*/
//Access the first line of loans.txt
String line = br.readLine();
//Read the # of lines in loans.txt
LineNumberReader read = new LineNumberReader(new FileReader("loans.txt"));
//Assign the # of lines to count
int count = 7;//read.getLineNumber();
Policy_Number.append(count + " ");
//Item being looked by the String Tokenizer
String Item = null;
//For loop, looping the # of times a line must be read
for(int x = 0; x < count; x++){
//While Line is not empty, proceed
while ( line != null )
//Read individual words of the line from loans.txt
StringTokenizer tokenizer = new StringTokenizer(line, "|");
Item = tokenizer.nextToken();
//While the line has more words
while(tokenizer.hasMoreTokens() )
//If Word equals "The" add 1 to the sum
if(Item == Policy_Num_Entered){
//Fill in policy Number
Policy_Number.append(Item);
Item = tokenizer.nextToken();
//Fill in First and Last Name
Name.append(Item);
Item = tokenizer.nextToken();
//Fill in Address
Address.append(Item);
Item = tokenizer.nextToken();
//Fill in City, State, ZIp Code
City_St_Zip.append(Item);
Item = tokenizer.nextToken();
//Fill in Loan Balance
LoanBal.append(Item);
Item = tokenizer.nextToken();
//Fill in Loan Effective Date
LoanEffDate.append(Item);
Item = tokenizer.nextToken();
//Fill in Maturity Date
MatDate.append(Item);
Item = tokenizer.nextToken();
//Take all the words that are left to fill in Notes
Notes.append(" " + Item );
Item = tokenizer.nextToken();
//Item found so change to 1
sucess = 1;
//Break out of the loop
break;
}//end of If
//Grab the next word
Item = tokenizer.nextToken();
}//end of while tokenizer
//Read the next line
line = br.readLine();
}//end of while
}//for loop
if(sucess == 0)
JOptionPane.showMessageDialog(Finalapp.this, "I'm sorry the Policy " +
Policy_Num_Entered + " was not found. Please try "+
"again.");
//Close the buffered Reader, and close the .dat file
br.close();
}//End of try
//Catch any errors that may have occured in the reader
catch(IOException exception)
exception.printStackTrace();
}//end of catch
}//end of GetFile

Similar Messages

  • Buffered reader need help

    Hello!
    I'm useless at java and am trying to complete a piece of code i just don't get!
    I'm reading in a text file and don't know how to complete the buffered reader section of it can anyone help!
    p
    the code is as follows.
    // Author:
    // Date:
    // The creation of the League class
    // saved as League.java to hold and manipulate icehockey team data
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    class League
    private static Team teams[]=new Team[6];
    League()
    String tName;
    String tNickname;
    String nPlayed;
    String nWon;
    String nLost;
    String nDrawn;
    try
    FileReader fr=new FileReader("Results.txt");
    //got the following syntax from p436
    BufferedReader br=new BufferedReader(fr);
    //confused!!!!     
    int i=0;
    while()
    // dunno if this is right!
    StringTokenizer st = new StringTokenizer(fr);
    while (st.hasMoreTokens())
    //will this work?
    tName=inputStream.sval;inputStream.nextToken();
    tNickname=inputStream.sval;inputStream.nextToken();
    nPlayed=(int)inputStream.nval;inputStream.nextToken();
    nWon=(int)inputStream.nval;inputStream.nextToken();
    nLost=(int)inputStream.nval;inputStream.nextToken();
    nDrawn=(int)inputStream.nval;inputStream.nextToken();
    //whats this bit about? new team instance to be written!
    //teams=;
    i++;
    fr.close();
    br.close();
    //catch exception thing wrote this dunno if it works or not
    catch (Exception e)
    if (e instanceof FileNotFoundException)
    system.out.println("Filename"+Results.txt+"not found")
         //     public int getSize()
                   //to be written
         //     public Team getTeam(int i)               
                   //to be written

    try somethign along these lines...
        try {
            BufferedReader in = new BufferedReader(new FileReader("infilename"));
            String str;
            while ((str = in.readLine()) != null) {
                process(str);
            in.close();
        } catch (IOException e) {
        }

  • Buffered reader / data inputstream

    I need to find out how to enter array numbers in from the keyboard
    i think it might be by using buffered reader, but i dont know th exact code can
    anybody help me!
    Cheers

    Do you need to keep array of numbers?
    It's simply and not powerfull solution:
    import java.io.*;
    import java.util.Vector;
    public class test
    public static void main (String argv[])
    BufferedReader theIn = new BufferedReader (new InputStreamReader (System.in));
    int nValue;
    int nSumma = 0;
    Vector theItems = new Vector (0, 10);
    while (true)
    try
    nValue = Integer.parseInt (theIn.readLine ());
    nSumma += nValue;
    theItems.addElement (new Integer (nValue));
    catch (Exception e)
    break;
    System.out.println ("Summa: " + nSumma);
    }

  • Buffered Reader IO

    Hi Friends,
    Have a unusual problem.
    I am trying to read a file using buffered reader api as:
    testHandle = new BufferedReader(new FileReader("Test.DAT"));
    but when i do
    while(...){
    String line = testHandle.readLine();
    System.out.println(line);
    the output is :
    My Name is Vishal.
    ello
    When in the file Test.DAT it is :
    # My Name is Vishal.
    Hello
    and if i add * in the Test.DAT file like this
    *# My Name is Vishal.
    Hello
    Then It prints
    # My Name is Vishal.
    ello
    Not able to understand why it is skipping the first letter (zeroth character of every line from the file) .
    Need your help on this.
    Thanks,
    Vishal

    You must be skipping some character(s), which you're not showing in the code snippet you posted. File I/O doesn't just skip over them - so there must be a bug in your code which you have omitted here.

  • MIO 6601 Counter, Perform Buffered Read and Simple Read

    I have an application written in C++ where I would like to use the 6601 as the time base for all of the boards, so I would like to be able to query the current value of the counter. I also have a external signal that I want time tagged in the buffer. I have used example programs for the Simple Read and the Buffered read and they both work successfully individually.
    If I try and combine them by setting up the counter with the following statement:
    iStatus = GPCTR_Set_Application(iDevice, ND_COUNTER_3, ND_BUFFERED_EVENT_CNT);
    and try to read the current value of the counter with:
    iStatus = GPCTR_Watch (iDevice, ND_COUNTER_3, ND_COUNT, puiCurrentTime);
    I always return a 0 for puiCurrentTime.
    Can
    I do both with a single counter? If not can I synchronize two counters one setup for the buffered read the other for the simple read.
    Thanks

    The second NIDAQ function call (GPCTR_Watch) will not work with Buffered Acquisition, because it is designed for simple read only. That might be the reason why puiCurrentTime always returns a zero.
    Regarding the second issue, you can do both tasks with a single counter, by configuring it as buffered first, and completing the operation, and then configuring it as single, and completing also the operation. Nevertheless, there is no way to configure it as buffered and work with it as single reader, or viceversa. You must use two for performing an operation such as that. Thus, if you want to synchronize both of them, I would suggest you to read the following document which talks about it.
    Well, I hope all of this info is helpful for you.
    Aguila
    Attachments:
    Multicounter_Synchronization_App_Note.doc ‏55 KB

  • Difference between Buffered Read and Read Mode on DataSocket Open

    What are the behavior differences when opening a DataSocket connection with a Buffered Read verses Read?

    Mlenz,
    You can learn about buffering data from our website, or in the LabVIEW help.  By using the Datasocket Buffered Read, you are enabling Client-side Buffering.  If you do not use a Buffered Read, then the LabVIEW does not store the values in a buffer, which are written when the value changes.
    Hope this helps,
    TheDillo

  • Trouble Implementing a Buffered Reader

    Any corrections would be very helpful. Thank you very much in advance for your kind assistance.
    public void selectRestaurant (int args[]) throws IOException{
                    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
                    boolean fineDining = true;
                    int nInput;
                    while(fineDining){
                        String inputString = input.readLine();
                        try{
                            nInput = Integer.parseInt(inputString);}
                        catch(NumberFormatException exc) {
                            System.out.println("Invalid entry");
                            nInput = 0;
                        switch(nInput){
                            case 1:
                            weight = weight + 10;
                            break;
                            case 2:
                            weight = weight + 15;
                            break;
                            case 3:
                            weight = weight + 20;
                            break;
                            case 4:
                            weight = weight - 20;
                            break;
                            default:
                            System.out.println("Please select a number between 1 and 4.");
                        }Edited by: 809632 on Nov 11, 2010 4:52 PM

    I have another class called MyInput that reads info from the Buffered Reader that looks like this:
    import java.io.*;
    class MyInput
      public static String readString()
        BufferedReader keyboard
          = new BufferedReader(new InputStreamReader(System.in), 1);
        String string = " ";
        try
          string = keyboard.readLine();
        catch (IOException ex)
          System.out.println(ex);
        return string;
      public static int readInt()
        return Integer.parseInt(readString());
    }But I can't seem to get the two classes to interact with each other. And a buffered reader never actually appears. When I run the method it just looks like I'm entering a parameter. Thank you so much in advance for your help.

  • Buffered Reader question.

    I am writing a program that reads data from multiple text files.
    When the program would need to read data from a different file I just reasigined the Buffered Reader object. For example:
    reader = new BufferedReader(new FileReader(new File(<name of first file>)));
    reader = new BufferedReader(new FileReader(new File(<name of second file>)));
    Is this a good method to use, or is it better to instanciate a new buffered reader object for each file?

    It is fine, the old reader will be GCed after a while.
    However, you might want to close the stream before just dumping the old one, as OSes have a limit on the number of files an app can open at one time. Plus it might leave the file locked, so other apps can not use said file.

  • Gurus..need help in reading data from virtual infocube

    Gurus,
    I have to read data from an virtual infocube...I am trying to use FM RSDRI_INFOPROV_READ to read data but it doesn't work..
    I am doing exactly what has been done in the demo program RSDRi_INFOPROV_READ_DEMO...
    Please help me...its really URGENT...
    Thanks
    sam

    Check out this thread....
    must be helpful
    Re: Read data from 0BWTC_C02 via ABAP

  • Help on Read

    Hi,
    Need some help on read statement.
    I need to read the records which starts with some character and need to specify the same in where condition as below.
    read table i_itab
         into w_itab
         with key objnr = w_itab-objnr
              stat CS 'E'
              Binary search.
    Getting error as should not use CS in the read statement. How to read the records which starts with letter 'E' only in this case.
    Can anyone help me out in this.
    Regards,
    Ram

    You should be able to do a binary search to get the first record and then do indexed reads to get subsequent records.
    Something like:
    DATA tab_index LIKE sy-tabix.
    SORT i_itab BY objnr stat.
    IF sy-subrc = 0.
      tab_index = sy-tabix.
    ENDIF.
    WHILE sy-subrc = 0.
      IF w_itab-stat CS 'E'.
    * process record.
      ENDIF.
      tab_index = tab_index + 1.
    READ TABLE i_itab INDEX tab_index.
      IF sy-subrc = 0.
      IF i_itab-objnr <> w_itab-objnr.
          sy-subrc = 9.
        ENDIF.
      ENDIF.
    ENDWHILE.
    Rob
    Message was edited by: Rob Burbank

  • Buffered Reader Question about wrapping around another Reader

    I'm reading about BufferedReaders and in the API the following paragraph reads:
    In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
    BufferedReader in = new BufferedReader(new FileReader("foo.in"));
    I was wondering if somebody could explain their reasoning in slightly less complicated terms...I can't really figure out what their reasoning is. Thanks

    If every time you wanted to read a character, you had to talk to the hard disk device, it would be very slow. This is because communicating with the disk is thousands of times slower than communicating with main memory.
    The buffered reader reads in chunks, buffers those data, and allows you to request them one character at a time.

  • Buffered Reader from  a JTextArea?

    Hi everyone,
    can anyone please tell me how i can get a buffered reader from a JTextArea? This is what I would like to do where the following gets displayed in the JTextArea
    Please enter your name: (user enters data here)
    Please enter your id number: (user enters id number here)
    I had coded this using the System.in but now trying to convert to a GUI
    Regards,
    M

    Hi there,
    I can't use get text as I will already have the other data that is written in the text area there as well, so it will get all the text. I need to be able to write stuff and then read the next line from what I have written. For example using my the command prompt:
    static BufferedReader br = new BufferedReader(
                                                     new InputStreamReader(System.in));
    System.out.print("Enter choice : ");
                System.out.flush();
                String choiceStr=null;
                try
                    choiceStr = br.readLine();
                } catch (IOException ioe)
                    System.out.println("Error reading choice.");
                    System.exit(1);
                int choice = -1;
                if (choiceStr.length() > 0)
                    choice = Integer.parseInt(choiceStr);
                switch (choice)
                    case 0: ....
                }On screen it would have wrote Enter choice: (user puts "7" )
    when the 7 and then /r is pressed then it will read in the 7 only.
    Thanks, M

  • Buffered Reader or String Buffer size.

    Hi.
    Is it possible to limit the size of a Buffered Reader input from the keyboard to a specific number? how would one go about it?

    I would like to limit the size of the buffered reader to ensure a minimum or maxim number of input is put in. I tried using the ensureCapacity class but there seems to be a problem in calling the class. the code is below
    import java.io.*;
    import java.awt.*;
    public class getUserString {
         public static void main (String [] args) throws Exception {
              int levl, x, load;
              String s1, s2;
              String input = " ";
              StringBuffer buf = new StringBuffer();
              System.out.println ("Enter a string of at least 4 characters");
              System.out.println ("Please do not enter a character more than once");
              BufferedReader mark = new BufferedReader(new InputStreamReader(System.in));
              mark.ensureCapacity(4);
              try{
                   s1 = mark.readLine();
                   System.out.println ("These are the characters you have entered: " + s1);
              catch(IOException e) {
                    e.printStackTrace();
    }

  • Adobe Reader XI 11.0.3 Help Adobe Reader XI Help not working!!

    Dear All,
    I've got the below error when click on : Help>Adobe Reader XI Help
    Please suggest the solution how to fix my reader help.
    Also followed following link to trouble shoot but no luck!!
    http://helpx.adobe.com/acrobat/kb/error-online-help-content-cannot.html
    Your help is very much appreciated.
    Regards,
    NEYIGAPULA

    Hi Pat,
    Here is the solution worked but not sure we can implement this or not.
    Installed Adobe AIR
    Installed Adobe Help Manager
    - Downloaded offline PDF
    Changed Adobe Reader EXE AcroRd32.exe compatibility settings to Windows XP SP3
    Launched Adobe Reader > Prompts "protected mode" windows to disable> Disabled Protected mode>Help working fine now
    Would you mind tell me the importance of Protected mode in New version of Adobe reader.
    Regards,
    Srinivas N

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

Maybe you are looking for

  • ITunes Match crashes during 3rd step when uploading songs to the iCloud

    Hello There, I have just one issue with iTunes Match which causes me to be slightly skeptical, although it is such an amazing way to listen to music ect. I have about 15000 songs and most of them were added on the iCloud, however only around 200 stil

  • Jdevloper11g Release 1: Error while running Bean in java

    Hello , I am getting error while running my HRFacadeClient.java [EclipseLink/JPA Client] Adding Java options: -javaagent:C:\Oracle\Middleware\jdeveloper\..\modules\org.eclipse.persistence_1.1.0.0_2-1.jar "C:\Program Files\Java\jdk1.6.0_29\bin\javaw.e

  • Tomcat 5.0.28 Crashing - Unexpected Error detected HotSpot Virtual Machine

    # An unexpected error has been detected by HotSpot Virtual Machine: # Internal Error (4A41564123414C4C530E4350500018), pid=2872, tid=2884 # Java VM: Java HotSpot(TM) Server VM (1.5.0_05-b05 mixed mode) --------------- T H R E A D --------------- Curr

  • PO comparison with similar materila number and line items

    Dear Friends,    I wish to know in a report how i classify the pos having similar material and line items in each other, Like po number is 12 and has material numbers 1, 2, 3 where po number 13 and has material 1,2,3. how i fetched the data from the

  • Qm with Batch chars

    Hi Gurus, I have big requirement which you might have faced this before, but very hard to understand. we have three components which goes in another component for eg: B1, B2 and B3 goes under component A1. B1 has got internal and customer specificati