Array of buffered reader

hi, how can i create an array of bufferredreader?
BuffererReader br = new BufferedReader(new FileReader(file))
like an array of strings?
String[] line = new String[10];
thanks so much!

Hey,
This what you mean (2 ways shown)
          try {
               // method 1
               BufferedReader[] readers = new BufferedReader[2];
               readers[0] = new BufferedReader(new FileReader("1.txt"));
               readers[1] = new BufferedReader(new FileReader("2.txt"));
               // method 2
               readers = new BufferedReader[] {
                         new BufferedReader(new FileReader("1.txt")),
                         new BufferedReader(new FileReader("2.txt"))
          } catch (FileNotFoundException e) {
               e.printStackTrace();
          }

Similar Messages

  • 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);
    }

  • 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

  • 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.

  • 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 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.

  • 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();
    }

  • 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) {
        }

  • 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.

  • Problems with buffered reads, buffers

    I have a few questions and issues that I have not been able to resolve with forum searches, I will try to keep them concise here.  #1 is the most important one to me.
    LabVIEW 7.1, Windows XP.
    Buffered Reads / Lost Data
    When error 10846 (AI Buffered Read, app unable to retrieve data from background acquisition buffer fast enough) occurs, I receive no data from the AI Buffered Read function for a period of time.  The error states data may be lost but it seems like I get NO data.  See the attached VI and JPG for examples.  The bottom graph shows a normal read while the top graph shows one with this problem.  I realize the AI Read error cluster is not handled in the acquisition loop.  From watching the backlog while the program runs, it seems the “dead spots” occur after the backlog reaches the buffer size.  When stopping acquisition, sometimes the error handler outside the loop reports 10846, sometimes it doesn’t (when the dead spots are occurring).  I can exaggerate dead spots with setups as follows:
      Buffer size 5, Scan rate 1000, # Scans to read 100
      Buffer size 10000, Scan rate 5500, # Scans to read 100
    The size of the dead spots and continuous data are proportional to the buffer size.
    Questions....
    1. Shouldn’t the AI Read function wait until it has # scans to read of valid data before returning?  For instance, scan rate of 100 and # scans to read of 1000 slows loop iteration speed to 0.1 Hz.  It seems like it is returning nothing for a period of time after the backlog reaches the buffer size.
    2. Error 10846 refers to the “data acquisition buffer.”  Is this the software buffer?  If so, what would LV refer to the hardware buffer as?
    3. I know the PCI-MIO-16E-1 has a hardware buffer, does this mean I can accurately acquire data over a period of time at a specified frequency (within limitations of the card of course) without having to worry about Windows bogging down due to delayed writes and such?
    4. Will hardware acquisition buffers generate an error if the data in them is lost/overwritten?
    5. I tried loading the acquisition VI (attached) onto a LV computer that has only a new USB-6008 connected but the AI read/config/clear functions were not available on that system.  Does this device not have hardware buffers (either I’m looking in the wrong places to find the answer this question and it uses different VIs OR it doesn’t have them). 
    6. The buffer/scan configuration listed above was used to exaggerate error 10846 and the accompanying dead spots but this problem has been intermittently plaguing a system I have been trying to understand/fix.  I have logged the backlog value as the program runs and see that it increases during certain processor-heavy state machine states and am hoping upgrading from 256MB to 2GB RAM will improve this.  Is there any reason I should not look at this as a solution?  (I am also planning on adding an error handler for AI Read into each acquisition loop so the problem can not continue to go on without detection!!!!!!!!!)
    7. Shouldn’t the AI Clear function report an error from the AI Read error cluster, even if it happened several reads earlier?  It seems like it does not do this; if I put the error handler in the acquisition loop I receive an error as soon as the backlog reaches the buffer size, EVERY time.  I thought I figured this out and changed the acquisition loop tunnels to shift registers... the error is reported each time this way; if AI Read will not acquire data if an error is fed into it in the first place then I guess I understand this one so I’m moving it to the bottom of the list.
    Thank you all for your time, I have been struggling to get up to speed with DAQ and LV and appreciate all the support.  I look forward to giving back to NI’s community in the future. 
    Regards,
    David.

    After all that typing I forgot the attachements, they should be on this post.
    I take it the AI.llb functions are "traditional DAQ."  I've started to experiment with the express VIs with newer hardware that I have been working with (USB-6008, USB-6211).  I will have to look at the DAQmx functions, it seems the express VIs are frowned upon by most.
    I have been working on modifying an older program that uses the traditional DAQ functions.  I will have to get more comfortable with DAQmx before attempting to change it over to them.  The attached example was wrote as I tried to understand what was going on in the program I was modifying.
    I believe the missing error handler on the AI Read function was causing unexpected (i.e. nothing returned) results the next time AI Read was called when the backlog exceeded the buffer value.  Subsequent calls to AI Read worked as expected unless the buffer overflowed again.
    Assuming this is correct the hardware buffer is the only thing I would like to understand better.  If it overflows what error (if any) will be generated in LV? 
    The other questions can be chalked up to the way traditional DAQ functions work and I think I've chased my tail enough to figure that out.
    Thanks,
    David.
    Attachments:
    acquire.jpg ‏25 KB
    acquire.vi ‏293 KB

  • 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/Writer

    Ok, I used the Buffered Writer to store an integer (or double) value. And I want to get it and store it to the variable bal But it's telling me I can't do it this way. try {
         BufferedReader in = new BufferedReader(new FileReader(name));
         bal = in.readLine();
         in.close();
         } catch (IOException e) {}When I use in.readLine() it says it needs an integer (or double, whichever bal is), so I tried useing in.readInt() and in.readDouble() but it can't find the symbol. So I'm assuming there is a different way? If so, could you point me in the direction to where I can read up on it?

    (or double, whichever bal is)
    What? You don't know what you declared it as, or is it "borrowed" code? Anyway, readLine() method returns a string so you cannot assign it to bal if it is declared as an int or double.
    bal = Integer.parseInt(in.readLine());
    bal = Double.parseDouble(in.readLine());

Maybe you are looking for

  • How do I change bbm back to older version??

    Hi there, I just updated my bbm version from 7 to 8. I do not like the new bbm and I'm wondering how do I change it back to the 7.0.1.2.3 version?? I tried backing up my phone via desktop manager but it didn't change my bbm back Please help!!! Thanks

  • How to optimize Database Calls to improve performance of an application

    Hi, I have a performance issue with my applications. It takes a lot of time to load, as it is making several calls to the database. And, moreover, the resultset has more than 2000 records that are returned. I need to know what is the better way to im

  • How to print the list shown in the finder

    I work as a photographer. For my clients I burn the pictures on DVD / CD. Some of my clients want a indexprint from the folder on the disk. How can print the list wich is shown in the finder? A screenshot doesn't work because there are often more ite

  • Accordion tabs

    Hai Adobe users,           I am using accordion container.Normally  in accordion using selectedindex=0 then first tab willbe open...but i want initially,all accordion tab willbe open.. How is it possible..plz guide me... Thanks & Regards, Sivamurugan

  • 09 inspection lot not getting generated

    Hi Friends , I have one material batch for which next inspection date is 7.6.2014 . I have activated 09 inspection type in material master . Now when I am executing QA07 for the material  with checkbox " To insp. stock at lot creation" selected and w