Reading Individual Lines of Text Into An ArrayList or Vector From A File

I am trying to read each individual line of text of a .txt file into an ArrayList or Vector. I seem to get the same results no matter which Object I am using (ArrayList or Vector). The text file is a comma-delimited text file to be used as a database. I want to separate each line as an individual record then dump it into an ArrayList or Vector and have them loop through a StringTokenizer() class so that I can be sure each line has the correct number of fields before I commit it to a serialization file. Currently, the proper amount of records seems to be forming in the initial part of the program, I am just remiss at properly placing them in the Vector, or StringTokenizer classes so I can further manipulate them. I'm using the LineNumberReader class to get line numbers to use as record numbers and for loop indexes. I'm not sure (obviously) if this is a correct way to do it or not.
Any help is greatly appreciated in advance.
Thanks for all your time.
int n = 0;
          try {
                * read each individual line and count it as a separate record. 
                * place each record into an array or may be a string if it has 9 tokens
                * if a record hasn't got 9 tokens, it isn't a record
                * place each array or string into a Vector
               in = new LineNumberReader(new FileReader(filename));
                         while ((record = in.readLine()) != null) {
                         n = in.getLineNumber();
                         rawData = new Vector();     
                         for (int i = 0; i < n; i++) {
                              rawData.add(record);     
                         if (record == null)
                         break;
*The following System.out.println() statement shows that all lines are correctly retrieved from the text file
*as separate records
                    System.out.println("Record No. " + n +  "= " + record);     
               //Debug
/** When these print lines execute it reveals that only the last record has been inserted into the Vector as
*    many times as I have records in the text file.
                    System.out.println("Number of Records = " + n);
                    System.out.println("VectorSize = " + rawData.size());
                    System.out.println("First rawDataElement = " + rawData.firstElement());
                    System.out.println("Second rawDataElement = " + rawData.get(1));
                    System.out.println("Third rawDataElement = " + rawData.get(2));
                    System.out.println("Fourth rawDataElement = " + rawData.lastElement());
*  Next run each record through a StringTokenizer to be sure that there the correct number of fields present
*  If it contains the correct number of fields, dump it into an alternate ArrayList or Vector.
*  As it is now, the StringTokenizer gives a NullPointerException
                    for (int i = 0; i < n; i++) {
                         StringTokenizer recordSet = new StringTokenizer((String) table.get(n), ",");
                             while (recordSet.hasMoreTokens()) {
                                 if (recordSet.countTokens() == 9) {
                                       data = new Vector();
                                       data.add((Object) recordSet.nextToken(","));
                                       System.out.println("Vector data size = " + data.size());
                                       System.out.println("Second dataElement = " + data.get(0));
                        System.out.println("String Tok recordSet = " + recordSet.countTokens());                                  System.out.println("Number of Records = " + n);
                    System.out.println("First dataElement = " + data.firstElement());
                    System.out.println("Second dataElement = " + data.get(0));
                    System.out.println("Third dataElement = " + data.get(2));
                    System.out.println("Fourth dataElement = " + data.lastElement());
               } catch (FileNotFoundException e) {
                    System.out.println(e);
               } catch (IOException e) {
                    System.out.println(e);
     }

I think your logic is broken.
rawData = new Vector();
creates a new instance of Vector for every record.
Your add() within a for loop adds the same record to the Vector n times. I think what you really want is something like this:in = new LineNumberReader(new FileReader(filename));
rawData = new Vector();
while ((record = in.readLine()) != null) {
    n = in.getLineNumber();
    rawData.add(record);     Mark

Similar Messages

  • Read a line of text in DataInputStream

    HI,
    I have a file with different data types, including text, with'\n' charater, integer and long, How could I read a line of text using DataInputStream?

    DataInputStream is for reading primitives, but I came up with a (untested) workaround:
    DataInputStream dis = new DataInputStream(new FileReader("bleh"));
    StringBuffer s = new StringBuffer();
    char c;
    while((c = dis.readChar()) != '\n') {
    s.append(c);
    String line = s.toString();
    StringBuffer is used because it gives better performance than String.
    NOTE: I have NOT tested this.

  • Is there a way to import text into an inDesign layout randomly from multiple word docs?

    i'd like to start out by thanking everyone for the help with the text box or stroke around text/paragraph, the advise has definitely helped.. What i'm wondering now is, is there a way to take multiple docs "wether it be a word doc or an indesign doc" and have them import or insert into our main layout in inDesign randomly or by taking one paragraph from each individual doc 1 after the other till each paragraph is inserted..
    To give you an idea:
    say i hav 4 text docs each doc is a category so to say, each with anywhere from 25 to 100 paragraphs.. each paragraph is it's own item or description.. each of these descriptions or items so to say needs to be in our layout each week, but randomly.. Currently we are using the cut and paste method to achieve the randomness in our layout.. I'm hoping theres an easier way..
    -if this is something inDesign can't do, might there be an alternative.. say an external app. that might achieve this for us?

    well.. we've come up with some sort of solution that seams to work well for what we want.. we combined each doc into an excel doc with each paragraph on it's own line.. then added extra columns in excel to input random numbers and letters -that can be changed weekly, so we can use the sort feature in excel to reorder all the paragraphs.. next we copy and paste from excel to inDesign, because importing an excel doc seams to be more agravation than it's worth..
    -this seems like it will work well for what we need to do, though curiouse if anyone else might have an alternative solution?
    as always thxs..

  • Copy text frames and paste in place from source file to opened docs

    Hello All,
    I have one source indd file which is having 10 small text frames (40pt square) in both pages (Facing pages, Left and Right) on a master page. In that master page there is no frame except that 10 small text frames and the text frame contains the paragraph style called "Cat_Cont".
    I have opened some files and I want to copy that 10 small text frames from the source file and paste in place into the opened InDesign Docs master pages. I hope while copying that text frames, paragraph style also would copy. Could anyone help for this, please?
    If anything not clear plz let me know.
    Thanks in Advance,
    Thiru

    Use TextFrame.duplicate()

  • Reservation line item text - non update issue

    Hi,
       We have a custom BDC (call tran) to create reservation. One of the fields for the reservation is line item text. We had this program from July 2008 onwards and we have no issues. All of sudden from 01/15/09 , the line item text is not being populated in the reservation, but reservation creation is working as before. We checked our system, there is no change to that program and infact we had only 2 transports on that day and they are related to FI and not related to MM or reservation at all.
    We did all our debugging, but this is inside a wrapper RFC and the RFC is called from EAI subsystem. (Tibco) The SQL trace and RFC trace shows all data of RESB being updated except this text. We are going crazy on this since it is such a simple BDC program and working fine so far and stopped all of sudden.
    My question is, are there any config which all of sudden made this field not available for input or something like that? I tried in config, but I couldn't find anything.
    Can you help on this? Thanks,
    The other crazy parts are,
    1. We tried writing the BDCTAB into a unix file, but the file is not created - one of the reason could be the user is CPIC user and may not have authorization to write to unix inspite of this user has sap all access
    2. We tried writing the dump into a custom table, but even that is not working. But when we execute this in SE37 manually, it is creating both unix file (in development) and updating the table as well.
    Regards,
    Sundar.

    It's sure that something changed between the last run and 01/15/09. A few ideas :
    - When the program is run, start an authorization trace, and give missing authorizations to CPIC until there is no more authorization problem (this is the most important thing to do first !)
    - Make sure that you program displays correctly all CALL TRANSACTION messages and exceptions also.
    - Analyze customizing imported between the 2 runs of this program (look at transport requests in the import queue log).
    - "Save" importing parameters so that to redo the test (with CPIC user) :
    -- change the program to write the BDCDATA to a batch input session (BDC_OPEN_GROUP, etc., SM35), and so test it later.
    -- save them to test data as indicated by [note 517767 Automatically generate test data at function module call|http://service.sap.com/sap/support/notes/517767]

  • More than 1 line of text when using text generator from file?

    hi
    have 8 line blocks of text to show onscreen.
    would like to use text generatorn>from file
    all they seem to print is one line.
    is there a work around?
    have trhied soft returns and paragraphs on saved text file.
    no change.
    anyonre know how to get 2 or more lines of text?
    thanks in addvance!

    Select the File generator layer and in the Inspector, select the Layout pane and in Layout controls, set the Layout Method to Paragraph.  Narrow your margins and the text will "flow" into multiple lines.
    You can also keyframe the paragraph layout position. [Probably more info than you want here.]
    That said, you can only display *one line* at a time per File Generator. (If you're up to date with Motion [v5.1.2], you can use more than one File generator.) The generator does not accept any other characters for returns other than newline and carriage return.
    I've never tried it, but thinking about it, you can set Tab stops in the Paragraph layout (double click in the layout rectangle and a ruler should appear over the top -- right click on the ruler to set tabs). If you go back into the original text file and where you need to break lines into two or more, setting a left tab stop in the layout very near the end of a line might force the tabbed text into the next line (did I make that clear enough??)

  • How to handle multiple threads to read one line from a file each time?

    Dear Sir or Madam,
    I'm new to multiple threads java programming. What I want to do is as following:
    1. I'm writing a program to read one line of text from a very large file, and then do some process on this one line of text, then read the next line of text from this file, then process on this line of text, ...... When reach the end of the file, close the file.
    This is a single thread scenario.
    2. To fullly untilized computer resource, I want to create multiple threads to process this large file.
    One thing is very important is that each line of text in the large file has to be read sequentially. This means that the first line of text in the large file is read first, then the second line, then the third line ......
    My question is that if I create multiple threads to process the same file, how can I make sure that different threads will read the line of text from the same file sequentially?
    I don't have enough experience on java multiple threads programming, so it will be very appreaciated if you can help me on this as soon as you are available.
    Thanks and regards,
    Steven Wu

    A better solutoin would be to have a single thread that reads each line an puts it into a queue, and then multiple threads reading from the queue to process these lines.
    This will only be effective if the amount of processing to be done on each line is very large compared to how long it takes to read the line, or if you have more than one CPU on your machine.

  • Reservation line item text non - update

    Hi,
       We have a custom BDC (call tran) to create reservation. One of the fields for the reservation is line item text. We had this program from July 2008 onwards and we have no issues. All of sudden from 01/15/09 , the line item text is not being populated in the reservation, but reservation creation is working as before. We checked our system, there is no change to that program and infact we had only 2 transports on that day and they are related to FI and not related to MM or reservation at all.
    We did all our debugging, but this is inside a wrapper RFC and the RFC is called from EAI subsystem. (Tibco) The SQL trace and RFC trace shows all data of RESB being updated except this text. We are going crazy on this since it is such a simple BDC program and working fine so far and stopped all of sudden.
    My question is, are there any config which all of sudden made this field not available for input or something like that? I tried in config, but I couldn't find anything.
    Can you help on this? Thanks,
    The other crazy parts are,
    1. We tried writing the BDCTAB into a unix file, but the file is not created - one of the reason could be the user is CPIC user and may not have authorization to write to unix inspite of this user has sap all access
    2. We tried writing the dump into a custom table, but even that is not working. But when we execute this in SE37 manually, it is creating both unix file (in development) and updating the table as well.
    Regards,
    Sundar.

    It solved by itself

  • Reading text from a file

    hi I have a text file which have the following lines of text.
    1. S. Amer-Yahia, P. Case, T. R�olleke, J. Shanmugasundaram, and G.Weikum. Report
    on the DB/IR Panel at SIGMOD 2005. In SIGMOD, June 2005.
    2. D. Carmel, Y. S. Maarek, M. Mandelbrod, Y. Mass, and A. Soffer. Searching XML
    Documents via XML fragments. In SIGIR, New York, USA, 2003.
    3. S. Ghita W. Nejdl P. Chirita, R. Gavriloaie and R. Paiu. Activity Based Metadata
    for Semantic Desktop Search. In ESWC, Greece, May 2005.
    4. V. Sinha and D. R. Karger. Magnet: Supporting Navigation in Semistructured Data
    Environments. In SIGMOD, June 2005.
    Now I want to read each line of text like:
    S. Amer-Yahia, P. Case, T. R�olleke, J. Shanmugasundaram, and G. -------------- from the first line and
    D. Carmel, Y. S. Maarek, M. Mandelbrod, Y. Mass, and A. Soffer. ---------- from the second line and so on.
    can anybody please help me how can I read like this.
    Regards,

    Please don't cross-post in multiple forums. This thread is active in the beginners forum, and let's leave it at that. Cross-posting will anger those who have tried to help you and convince others not to try to help you. Do it again and many (including me) will put you on their ignore list.

  • How to read a line of string?

    Hi, I am very new to java programming. Can anyone show me a method of a simple way to read a line of characters into a string? I look over the internet but all seems awfully complicated like easyReader..etc which you have to import more other classes to make it to work. I just need it to be as simple as just to read a line into string.
    Thank you...

    Hi, try this..
    import java.io.*;
    public class rt
         public static void main(String[] args) throws IOException
              BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
              String s = r.readLine();
              System.out.println(s);
    }hope this helps,
    mfg
    bbm1277

  • The Line item text transfer from SD-Billing Document to FI Doc(Accounting)

    Hi Experts,
    Actually in Standard process the Line item text doesnu2019t get transferred to FI Doc-Accounting Document.
    But we have a need to ensure that the Line item text of a material gets transferred from a Billing Document to  Accounting document.
    Please advice how can we achieve this.
    Thanks in Advance
    Montee

    Hi,
    If you want to populate the field SGTXT in FI tables (BSID, BSAD, BSEG,...) check the enhancement SDVFX002. So, in the function EXIT_SAPLV60B_002 you can populate XACCIT-SGTXT when you run the invoicing process.
    I hope this helps you
    Regards,
    Eduardo

  • Method to return ArrayList or Vector doesn't work, why?

    Hi, I try to return a ArrayList or Vector from a method but it does not work.. wondering why and how to fix it? Thanks:)
    class Class1{
          public static main(...){
              Class2 test = new Class2();
              ArrayList<String> resp = test.class2method(...);
              if(resp.get(4).equals(...)) {        
    class Class2{
        public ArrayList class2method(int NumInt1, int NumInt2, ...) {
           ArrayList<String> arrayTesting = new ArrayList<String>(13);
           responses.set(2, Integer.toString(NumInt1));
           responses.set(3, Integer.toString(NumInt2));
           responses.set(4, Integer.toString(NumInt3));
           responses.set(5, Integer.toString(NumInt4));
           responses.set(6, Integer.toString(NumInt5));
           return responses;
    }

    what is responses? don't you want to return
    arrayTesting?yes, responses is arrayTesting, sorry did notmention
    that.what do you mean? is the code you posted a typo or
    what you actually have in your code?It's more than 1000 lines codes so I decided not to posted them but here is part of them. My point is that i tried to return a ArrayList or Vector even with a simple code, it does not work. Thanks for your help.
    public class DemoScript {
        public DemoScript() throws IOException {
            // register the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    System.out.println("close prog");
                     endApp();
        public void endApp() {
            System.out.println("done!");
            System.exit(0);
         public static void main(String[] args) {
              Parameters p = new Parameters();
              VMF vm = null;
                   //Elements: [0]time, [1]MsgType, [2]NumInt1, [3]NumInt2, [4]NumInt3, [5]NumInt4, [6]NumInt5, [7]NumLong,
                   //               [8]String1, [9]String2, [10]String3, [11]String4, [12]String5
    //               ArrayList<String> responses = new ArrayList<String>(13);
              try {
                   MyScript my = new MyScript();
                   if(args.length == 5) {
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]);
                       p.guiHost = args[3]; p.guiPort = Integer.parseInt(args[4]);
                  } else if(args.length == 4) {
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]); p.guiHost = args[3];
                  } else if(args.length == 3){
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]);
                  } else if(args.length == 2){
                       p.vmHost = args[1];
                  } else {
                       System.out.println("Usage: java MyScript [port #] [voice mail hostname] <voice mail socket #> <GUI hostname> <GUI socket #>");
                       System.out.println("Default: <voice mail socket #> = "+p.vmPort+", <GUI hostname> = "+p.guiHost+", <GUI socket #> = "+p.guiPort);
                       System.exit(-1);
    //               String hostname;
                   //int port;
                   /* Check for input arguments */
                   //if(args[0] != null){
                   //     port = Integer.parseInt(args[0]);
                   //     hostname = args[1];
                   //} else {
                   //     port = 2000;
                   //     hostname = "10.0.0.228";
                   //System.out.println("tews");
                   vm = new VMF(p.vmHost, p.vmPort, p.guiHost, p.guiPort);
                   vm.logon();
                   //vm.portAbort(4);/*
                   vm.portCapture(3, 0);
                   //vm.portAbort(4);/*
                   //vm.portOnhook();
                   //vm.portOffhook();
                   ////vm.portStop(3);  //to stop a port current operation
                   //vm.portWaitring(); //vm will not resp until port detects ring
                   //vm.portOffhook();
                   //vm.portGetdigits(5, 7);
                   //vm.portDialdigits("201");
                   //for(int i=0;i<100000000;i++);
                   //vm.portCallprogress(3, 0, 10);
                   //System.out.println("d");
                   //for(int i=0;i<1000000;i++);
                   //vm.portGetdigits(5, 7);
                   //vm.portRecordfile(30, 1, "\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portClearDTMF();
                   //vm.portPlayfile("\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portPlayprompt(2);
                   //vm.portSpeaknumber(3845);
                   //vm.portSpeakdigits("1639123478866478909");//75655656566657867867*");
                   //vm.portExternalcall(4, "933");
                   ArrayList<String> response = vm.portInternalcall(2, "201");
                   System.out.println(response.get(4));
                   if(response.get(4).equals("DONE")) {
                        vm.portPlayprompt(1); vm.portPlayprompt(2);
                   } else if(response.get(4).equals("GONE")) {
                   vm.portSpeakttsstring("hello. This will create ");//a project with all of the proper SWT and JFace imports. Version 4.1.1 latest build released (SWT visual inheritance, enhanced SWT GridLayout support, non-visual beans, custom !!!SWT widgets, code generation enhancements, expose property, etc.)");
                   vm.portRelease();
                   vm.logoff();
                   vm = new VMF(p.vmHost, p.vmPort, p.guiHost, p.guiPort);
                   vm.logon();
                   vm.portCapture(Integer.parseInt(args[0]), 0);
                   vm.portOnhook();
                   vm.portOffhook();
                   //          vm.portGetdigits(5, 7);
                   //vm.portRecordfile(30, 1, "\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portClearDTMF();
                   //vm.portPlayfile("\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   vm.portPlayprompt(86);
                   //          vm.portSpeaknumber(3845);
                   //vm.portSpeakdigits("1639123478866478909");//75655656566657867867*");
                   //vm.portExternalcall(4, "933");
                   //vm.portInternalcall(9, "82045");
                   //vm.portSpeakttsstring("hello. This will create");// a project with all of the proper SWT and JFace imports. Version 4.1.1 latest build released (SWT visual inheritance, enhanced SWT GridLayout support, non-visual beans, custom !!!SWT widgets, code generation enhancements, expose property, etc.)");
                   vm.portRelease();
                   vm.logoff();
              } catch (IOException e) {
                   e.printStackTrace();
              } catch (InterruptedException e) {
                   //catch "STOP PORT"
                   vm.logoff();
    class VMF {
        public ArrayList<String> portInternalcall(int rings, String dial_string) {
             if (logon_status == 0) {
                   System.err.println("Error: logon required");
                   logoff();closeAndExit();
              } else if (capture_status == 0) {
                   System.err.println("Warning: portCapture required");logoff();closeAndExit();
              } else if (rings <1 || rings >999 || !checkDigits(dial_string)) {
                   System.err.println("Warning: portInternalcall( [1-999] , \"[0-9,A-D,F,P,a-d,f,p,*,#]\" )");
             breakString(dial_string);
             ostruct.write("", "IVR", "123", 188, captured_port, rings, 0, 0, 0, 0, str1, str2, str3, str4, str5);
             sendToGUI("s", "", "IVR", "123", "188", Integer.toString(captured_port),
                       Integer.toString(rings), "0", "0", "0", "0", str1, str2, str3, str4, str5);
             readStream();
             recToGUI("r", Integer.toString(MsgType),Integer.toString(NumInt1),Integer.toString(NumInt2),
                        Integer.toString(NumInt3),Integer.toString(NumInt4),Integer.toString(NumInt5),
                        Integer.toString(NumLong),String1,String2,String3,String4,String5);
              responses.set(2, Integer.toString(NumInt1)); responses.set(3, Integer.toString(NumInt2));
              responses.set(4, Integer.toString(NumInt3)); responses.set(5, Integer.toString(NumInt4));
              responses.set(6, Integer.toString(NumInt5));
              return responses;
    }

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • How to input data into an arraylist from a text file?

    I am trying to take data from a text file and put that data into an arraylist. First here is the text file:
    [item1, 10, 125.0, item2, 10, 12.0, item3, 20, 158.0]
    3
    4530.0
    [item5, 65, 555.5, item4, 29, 689.0]
    2
    56088.5
    [item7, 84, 34.5, item6, 103, 0.5, item8, 85, 1.36]
    3
    3065.1The text between the [ ] is the output from my arraylists. I have three arraylists. The first [ ] belongs to arraylist A, the second to arraylist B, and the third to arraylist C. The format of the arraylists is this:
    <item name>,<# in stock>,<value of one item>
    The first number below the arraylists in the text file represents the number of items in the list. The second number below the arraylists represents the total value of the items in the arraylists.
    Here is the class file I have (yes, it does everything):
    import java.io.*;
    import java.util.Scanner;
    import java.util.ArrayList;
    public class Inventory extends Object
         public int toAdd = 0;
         private boolean done = false;               //Are we done yet?
         public String strItemName;                    //The name of the item type.
         public int intNumInStock;                    //The number in stock of that type.      
         public double dblValueOfOneItem;          //The value of one item.
        public String strNumberInStock;               
        public double dblTotalValueA;               //The total value of warehouse A.
        public double dblTotalValueB;               //The total value of warehouse B.
        public double dblTotalValueC;               //The total value of warehouse C.
        public int intWarehouseAItemCount;          //Counter for items in warehouse A.
        public int intWarehouseBItemCount;          //Counter for items in warehouse B.
        public int intWarehouseCItemCount;          //Counter for items in warehouse C.
         ArrayList warehouseAList = new ArrayList();     //Create the Warehouse A ArrayList.                                   
         ArrayList warehouseBList = new ArrayList(); //Create the Warehouse B arrayList.
         ArrayList warehouseCList = new ArrayList(); //Create the Warehouse C arrayList.
         /** Construct a new Inventory object. */
         public Inventory()
              super();
         /**Add items to the Warehouse A ArrayList.*/
         private void createWareHouseA()
              System.out.println("!" + toAdd + " item types will be added to warehouse A.");
              //Cast
              String strNumInStock = Integer.toString(intNumInStock);
              String strValueOfOneItem = Double.toString(dblValueOfOneItem);
              this.strNumberInStock = strNumInStock;
              System.out.println("!Initial size of warehouseAList :  " +
                                                                warehouseAList.size());
              //Add items to the array List
              warehouseAList.add(this.strItemName);
              warehouseAList.add(this.strNumberInStock);
              warehouseAList.add(this.dblValueOfOneItem);
              System.out.println("!size of arrayList after additions " + warehouseAList.size());
         /**Add items to the Warehouse B ArrayList.*/
         private void createWareHouseB()
              System.out.println("!" + toAdd + " item types will be added to warehouse B.");
              //Cast
              String strNumInStock = Integer.toString(intNumInStock);
              String strValueOfOneItem = Double.toString(dblValueOfOneItem);
              this.strNumberInStock = strNumInStock;
              System.out.println("!Initial size of warehouseBList :  " +
                                                                warehouseBList.size());
              //Add items to the array List
              warehouseBList.add(this.strItemName);
              warehouseBList.add(this.strNumberInStock);
              warehouseBList.add(this.dblValueOfOneItem);
              System.out.println("!size of arrayList after additions " + warehouseBList.size());
         /**Add items to the Warehouse C ArrayList.*/
         private void createWareHouseC()
              System.out.println("!" + toAdd + " item types will be added to warehouse C.");
              //Cast
              String strNumInStock = Integer.toString(intNumInStock);
              String strValueOfOneItem = Double.toString(dblValueOfOneItem);
              this.strNumberInStock = strNumInStock;
              System.out.println("!Initial size of warehouseCList :  " +
                                                                warehouseCList.size());
              //Add items to the array List
              warehouseCList.add(this.strItemName);
              warehouseCList.add(this.strNumberInStock);
              warehouseCList.add(this.dblValueOfOneItem);
              System.out.println("!size of arrayList after additions " + warehouseCList.size());
         /**Interpret the commands entered by the user.*/
         public void cmdInterpreter()
              this.displayHelp();
              Scanner cin = new Scanner(System.in);
              while (!this.done)
                   System.out.print(">");
                   //"line" equals the next line of input.
                   String line = cin.nextLine();
                   this.executeCmd(line);
         /**Execute one line entered by the user.
          * @param cmdLN; The command entered by the user to execute. */
          private void executeCmd(String cmdLN)
               Scanner line = new Scanner(cmdLN);
               if (line.hasNext())
                    String cmd = line.next();
                    //What to do when users enter the various commands below.
                    if (cmd.equals("help"))
                         this.displayHelp();
                    else if (cmd.equals("Q!"))
                         this.done = true;
                    else if (cmd.equals("F") && line.hasNext())
                         this.inputFromFile(line.next());
                    else if (cmd.equals("K") && line.hasNext())
                         int numItemsToAdd = Integer.valueOf( line.next() ).intValue();
                         this.toAdd = numItemsToAdd;
                         this.inputFromKeyboard(numItemsToAdd);
          /**What to do if input comes from a file.
           *     @param inputFile; The name of the input file to process.*/
          private void inputFromFile(String inputFile)
               Scanner cin = new Scanner(System.in);
               System.out.println("!Using input file " + inputFile + ".");
               System.out.print("!Enter the name of the output file: ");
               String outputFile = cin.next();
               System.out.println("!Using output file " + outputFile + ".");
              try
                   BufferedReader in = new BufferedReader(new FileReader(inputFile));
                   //Scanner in = new Scanner(new File(inputFile));
                   //Initialize the String variables.
                   String line1 = null;
                   String line2 = null;
                   String line3 = null;
                   String line4 = null;
                   String line5 = null;
                   String line6 = null;
                   String line7 = null;
                   String line8 = null;
                   String line9 = null;
                   System.out.println(in.equals(",") + " see?");
                   //System.out.println((char)(char)in.read() + " experiment");
                   /**This loop assigns values to the string variables based on the
                    * values on each line in the input file. */
                   while(in.readLine() != null)
                        line1 = in.readLine();
                        line2 = in.readLine();
                        line3 = in.readLine();
                        line4 = in.readLine();
                        line5 = in.readLine();
                        line6 = in.readLine();
                        line7 = in.readLine();
                        line8 = in.readLine();
                        line9 = in.readLine();
                   //Print the contents of each line in the input file.
                   System.out.println("!value of line 1: " + line1);
                   System.out.println("!value of line 2: " + line2);
                   System.out.println("!value of line 3: " + line3);
                   System.out.println("!value of line 4: " + line4);
                   System.out.println("!value of line 5: " + line5);
                   System.out.println("!value of line 6: " + line6);
                   System.out.println("!value of line 7: " + line7);
                   System.out.println("!value of line 8: " + line8);
                   System.out.println("!value of line 9: " + line9);
                /**Add items to the warehouses.*/
                   warehouseAList.add(line1);
                   warehouseBList.add(line4);
                   warehouseCList.add(line7);
                /**Add the item count and total value for warehouse A.*/
                   int intLine2 = Integer.valueOf(line2).intValue();
                   this.intWarehouseAItemCount = intLine2;
                   double dblLine3 = Double.valueOf(line3).doubleValue();
                   this.dblTotalValueA = dblLine3;
                /**Add the item count and total value for warehouse B.*/
                   int intLine5 = Integer.valueOf(line5).intValue();
                   this.intWarehouseBItemCount = intLine5;
                   double dblLine6 = Double.valueOf(line6).doubleValue();
                   this.dblTotalValueB = dblLine6;
                /**Add the item count and total value for warehouse C.*/
                  int intLine8 = Integer.valueOf(line8).intValue();
                  this.intWarehouseCItemCount = intLine8;
                  double dblLine9 = Double.valueOf(line9).doubleValue();
                  this.dblTotalValueC = dblLine9;
                /**Ask the user how many items to add or delete from inventory.*/
                  System.out.print("Enter the number to add to inventory for " +
                                                               warehouseAList.get(0) + ":");
                  String toAddOrDel = cin.next();
                /**Print the contents of all the warehouses. */
                   System.out.println(" ");
                   //Print the contents of warehouse A.
                   System.out.println("!--------------------------------");
                   System.out.println("!----------Warehouse A:----------");
                   System.out.println("!--------------------------------");
                   //Print the item list for warehouse A.
                   System.out.println(warehouseAList);
                   //Print the total amount of items in warehouse A.
                   System.out.println("Total items: " + this.intWarehouseAItemCount);
                   //Print the total value of the items in warehouse A.
                   System.out.println("Total value: " + this.dblTotalValueA);
                   System.out.println("!--------------------------------");
                   System.out.println("!----------Warehouse B:----------");
                   System.out.println("!--------------------------------");
                   //Print the item list for warehouse B.
                   System.out.println("!warehouseB: " + warehouseBList);
                   //Print the total amount of items in warehouse B.
                   System.out.println("Total items: " + this.intWarehouseBItemCount);
                   //Print the total value of the items in warehouse B.
                   System.out.println("Total value: " + this.dblTotalValueB);
                   System.out.println("!--------------------------------");
                   System.out.println("!----------Warehouse C:----------");
                   System.out.println("!--------------------------------");
                   //Print the item list for warehouse C.
                   System.out.println("!warehouseC: " + warehouseCList);
                   //Print the total amount of items in warehouse C.
                   System.out.println("Total items: " + this.intWarehouseCItemCount);
                   //Print the total value of the items in warehouse C.
                   System.out.println("Total value: " + this.dblTotalValueC);
                   in.close();
              catch (FileNotFoundException e)
                   System.out.println("!Error: Unable to open file for reading.");
              catch (EOFException e)
                   System.out.println("!Error: EOF encountered, file may be corrupted.");
              catch (IOException e)
                   System.out.println("!Error: Cannot read from file.");
          /**What to do if input comes from the keyboard.
           *     @param numItems; The total number of items that will be added to the
           *                      Warehouse(s). */
          public void inputFromKeyboard(int numItems)
               System.out.println("!You will be adding " + numItems + " items to " +
                                             "inventory from the keyboard. ");
               this.toAdd = numItems;
               Scanner cin = new Scanner(System.in);
               //Prompt user for name of output file.
               System.out.print("!Enter the name of the output file: ");
               String outputFile = cin.next();
               /**This loop asks the user for information about the item(s) and inputs
                 *them into the appropriate array.*/
               int count = 0;
               while (numItems > count)
                    //Item name.
                    System.out.print("!Item name: ");
                    String addItemName = cin.next();
                    //Number in stock.
                    System.out.print("!Number in stock: ");
                    String addNumInStock = cin.next();
                    //Initial warehouse.
                    System.out.print("!Initial warehouse(A,B,C): ");
                    String addInitWarehouse = cin.next();
                    //Value of one item.
                    System.out.print("!Value of one item: ");
                    String addValueOfOneItem = cin.next();
                    //Add or delete from inventory
                    System.out.print("!Enter amount to add or delete from inventory: ");
                    String strAddOrDelete = cin.next();
                    System.out.println("!Amount to add or delete: " + strAddOrDelete);
                    //Cast
                    int intAddNumInStock = Integer.valueOf(addNumInStock).intValue();
                    double doubleAddValueOfOneItem = Double.valueOf(addValueOfOneItem).doubleValue();
                    int intAddOrDelete = Integer.valueOf(strAddOrDelete).intValue();
                    /**Add intAddNumInStock with intAddOrDelete to determine the amount
                     * to add or delete from inventory (If a user wishes to remove items
                     * from inventory simply add negative values). */
                    intAddNumInStock = intAddNumInStock + intAddOrDelete;
                    System.out.println("!Inventory after modifications: " + strAddOrDelete);
                    this.strItemName = addItemName;
                    this.intNumInStock = intAddNumInStock;
                    this.dblValueOfOneItem = doubleAddValueOfOneItem;
                    //Put items into warehouse A if appropriate.
                    if (intAddNumInStock < 25)
                        //Increment the warehouse A item count.
                        this.intWarehouseAItemCount = this.intWarehouseAItemCount + 1;
                        //Calculate the total value of warehouse A.
                        this.dblTotalValueA = this.dblTotalValueA + intAddNumInStock * doubleAddValueOfOneItem;
                        //Create the warehouse A array list.
                        this.createWareHouseA();
                    //Put items into warehouse B if appropriate.
                    if (intAddNumInStock >= 25)
                        if (intAddNumInStock < 75)
                             //Increment the warehouse B item count.
                             this.intWarehouseBItemCount = this.intWarehouseBItemCount + 1;
                             //Calculate the total value of warehouse B.
                             this.dblTotalValueB = this.dblTotalValueB + intAddNumInStock * doubleAddValueOfOneItem;
                             //Create the warehouse B array list.
                             this.createWareHouseB();
                    //Put items into warehouse C if appropriate.
                    if (intAddNumInStock >= 75)
                        //Increment the warehouse C item count.
                        this.intWarehouseCItemCount = this.intWarehouseCItemCount + 1;
                        //Calculate the total value of warehouse C.
                        this.dblTotalValueC = this.dblTotalValueC + intAddNumInStock * doubleAddValueOfOneItem;
                        //Create the warehouse C array list.
                        this.createWareHouseC();
                     //display helpful information.      
                    System.out.println("!--------------------------------");
                    System.out.println("!" + addItemName + " is the item name.");
                    System.out.println("!" + addNumInStock + " is the number in stock.");
                    System.out.println("!" + addInitWarehouse + " is the initial warehouse.");
                    System.out.println("!" + addValueOfOneItem + " is the value of one item.");
                    System.out.println("!--------------------------------------------------");
                   //Increment the counters.
                    count++;
               /**Create and write to the output file. */
               try
                     //Use the output file specified by the user.
                    PrintWriter out = new PrintWriter(outputFile);
                 /**Write warehouse A details.*/
                      //Blank the first line.
                      out.println(" ");
                    //Write the array list for warehouse A.
                    out.println(warehouseAList);
                    //Write the amount of items in warehouse A.
                    out.println(intWarehouseAItemCount);
                    //Write the total value for warehouse A.
                    out.println(dblTotalValueA);
                 /**Write warehosue B details.*/
                   //Write the array list for warehouse B.
                    out.println(warehouseBList);
                    //Write the amount of items in warehouse B.
                    out.println(intWarehouseBItemCount);
                    //Write the total value for warehouse B.
                    out.println(dblTotalValueB);
                 /**Write warehouse C details.*/
                      //Write the array list for warehouse C.
                    out.println(warehouseCList);
                    //Write the amount of items in warehouse C.
                    out.println(intWarehouseCItemCount);
                    //Write the total value for warehouse C.
                    out.println(dblTotalValueC);
                    //Close the output file.
                    out.close();     
                catch (FileNotFoundException e)
                   System.out.println("Error: Unable to open file for reading.");
               catch (IOException e)
                   System.out.println("Error: Cannot read from file.");
               /**View the contents and the value of each warehouse.*/
               System.out.println("!---------------Inventory Summary------------------");
               System.out.println("!--------------------------------------------------");
               System.out.println("!--------------------LEGEND:-----------------------");
               System.out.println("!<item type>, <amount in stock>,<value of one item>");
               System.out.println("!--------------------------------------------------");
               System.out.println("!------------------Warehouse A:--------------------");
               System.out.println("!--------------------------------------------------");
               //Display Items in warehouse A.
               System.out.println(warehouseAList);
               //Total items in warehouse A.
               System.out.println("Total items: " + intWarehouseAItemCount);
               //Display total value of warehouse A.
               System.out.println("Total value: " + "$" + dblTotalValueA);
               System.out.println("!--------------------------------------------------");
               System.out.println("!------------------Warehouse B:--------------------");
               System.out.println("!--------------------------------------------------");
               //Display Items in warehouse B.
               System.out.println(warehouseBList);
               //Total items in warehouse B.
               System.out.println("Total items: " + intWarehouseBItemCount);
               //Display total value of warehouse B.
               System.out.println("Total value: " + "$" + dblTotalValueB);
               System.out.println("!--------------------------------------------------");
               System.out.println("!------------------Warehouse C:--------------------");
               System.out.println("!--------------------------------------------------");
               //Display Items in warehouse C.
               System.out.println(warehouseCList);
               //Total items in warehouse C.
               System.out.println("Total items: " + intWarehouseCItemCount);
               //Display total value of warehouse C.
               System.out.println("Total value: " + "$" + dblTotalValueC);
         /**Display a help message.*/
         private void displayHelp()
              System.out.println("!--------------------------------");
              System.out.println("! General Help:");
              System.out.println("!--------------------------------");
              System.out.println("! ");
              System.out.println("!'help' display this help message.");
              System.out.println("!'Q!' quit this program.");
              System.out.println("!--------------------------------");
              System.out.println("! Input File Specific Commands:");
              System.out.println("!--------------------------------");
              System.out.println("! ");
              System.out.println("!'F' <name> type F followed by the name of the " +
                                       "file to be used for input.");
              System.out.println("!---------------------------------------");
              System.out.println("! Input From Keyboard Specific Commands:");
              System.out.println("!---------------------------------------");
              System.out.println("! ");
              System.out.println("!'K' <number> type K followed by the number of " +
                                        "items that will be added. ");
              System.out.println("! ");
    }Program file:
    public class InventoryProg
         public static void main(String[] args)
              //Create a new Inventory object.
              Inventory test = new Inventory();
              //Execute the command interpreter.
              test.cmdInterpreter();
    }Right now I am stuck on this and I cannot progress any further until I figure out how to input the data in the text file back into a arraylist.
    Thanks in advance.

    Thanks but I figured it out. Heres a sample of the code i used to solve my problem:
    try
                           //Warehouse A BufferedReader.
                   BufferedReader inA = new BufferedReader(new FileReader(inputFileWarehouseA));
                   //Warehouse B BufferedReader.
                   BufferedReader inB = new BufferedReader(new FileReader(inputFileWarehouseB));
                   //Warehouse C BufferedReader.
                   BufferedReader inC = new BufferedReader(new FileReader(inputFileWarehouseC));
                   //Warehouse details BufferedReader.
                   BufferedReader inDetails = new BufferedReader(new FileReader(inputFileDetails));
                   //Will hold values in warehouse arraylists.
                   String lineA = null;
                   String lineB = null;
                   String lineC = null;
                   //Will hold the details of each warehouse.
                   String line1 = null;
                   String line2 = null;
                   String line3 = null;
                   String line4 = null;
                   String line5 = null;
                   String line6 = null;
                   //Get the item count and total value for each warehouse.
                   while(inDetails.readLine() != null)
                        line1 = inDetails.readLine();
                        line2 = inDetails.readLine();
                        line3 = inDetails.readLine();
                        line4 = inDetails.readLine();
                        line5 = inDetails.readLine();
                        line6 = inDetails.readLine();
               /**Assign the item count and total value to warehouse A.*/
                  //Cast.
                   int intLine1 = Integer.valueOf(line1).intValue();
                   double dblLine2 = Double.valueOf(line2).doubleValue();
                   //Assign the values.
                   this.intWarehouseAItemCount = intLine1;
                   this.dblTotalValueA = dblLine2;
                /**Assign the item count and total value to warehouse B.*/
                     //Cast.
                   int intLine3 = Integer.valueOf(line3).intValue();
                   double dblLine4 = Double.valueOf(line4).doubleValue();
                     //Assign the values.
                   this.intWarehouseBItemCount = intLine3;
                   this.dblTotalValueB = dblLine4;
                /**Assign the item count and total value to warehouse C.*/
                     //Cast.
                     int intLine5 = Integer.valueOf(line5).intValue();
                   double dblLine6 = Double.valueOf(line6).doubleValue();
                   //Assign the values.
                   this.intWarehouseCItemCount = intLine5;
                   this.dblTotalValueC = dblLine6;
                /**Put the items back into the warehouses arraylists. */
                   //Add items to warehouse A.
                   while((lineA = inA.readLine()) != null)
                        warehouseAList.add(lineA);
                   //Add items to warehouse B.
                   while((lineB = inB.readLine()) != null)
                        warehouseBList.add(lineB);
                   //Add items to warehouse C.
                   while((lineC = inC.readLine()) != null)
                        warehouseCList.add(lineC);
                   }(this isn't the whole try statement its pretty long)

  • How do I split each page into a PDF and name them after a line of text on the split page?

    All,
    I am running a report that is creating hundreds of letters to be sent to customers.  When I run the report it creates one large PDF (one letter = one page).  To help with a specific business solution I need to split each page into an individual PDF.  I know I can extract the pages using the extraction tool.  I have also been able to duplicate this from the Javascript console, but only with generic names.  The problem is that I need each PDF named after the customer's account number.  The account number is listed on the page that I am extracting, but I am having a hard time parsining the text on the pages to find it.
    I need to be able to turn each page into a seperate PDF and then rename that PDF to match the account number list on the page.
    The account number, is of course, different for every customer and has varied prefixes.  The line of text that I need to read starts like this:
    Account Number#: NJA00001
    I need to just pull the NJA00001.
    I would really love to automate this process.
    Can you help me with this?  Thanks in advance.
    PS: I am a little rusty on my Javascript, its been a couple years.

    This can probably be achieved with a custom-made script, but it's not possible to know for sure before seeing some sample files.

Maybe you are looking for

  • Tried to update to ios6.1, but after that my ipad show s the connect to itunes and stuck there.

    tried to upgrade my ipad from 6.0.1 to 6.1 yesterday, then got screen got stuck at connect to itunes pic. my itune is up to date.

  • Importing from iPhoto fail

    I am new to Photoshop and just installed Photoshop Elements 11 on my Mac OS X.  Everytime I try to import photos from iPhoto the import process will go through until it is almost finished, then a notification will pop up saying that the import failed

  • Mail forwarding with so_object_send

    Hi, I have the problem that when I resend/forward an existing mail with attachment with fm "so_object_send" the old receiver gets the mail a second time, although he is not assigned in the table "receivers". How can I avoid, this behavior??? Thanks f

  • Very Very Urgent --Su01***

    Hi BW Gurus I got a requirement like ,I need to give(or add)access to new business areas 2414 and 2415 for already existing user to view the reports..How I should add this access to the Role in SU01 or PFCG transaction .Appreciated if also let me kno

  • Many questions revolving around selling my Mac

    Hello, I have owned my Mac years, since the time it was first shipped out (The Intel Core Two Duo version at least) and I was just wondering if I could have a couple questions answered. 1. How can I safely transfer all of the data to an external HDD,