.txt file to arrays using Java -
I have a .txt file that contains document information (for 1400 documents). Each document has an ID, title, author, field and summary. A sample looks like this:
. 1. Experimental investigation of a wing aerodynamics in the slipstream. A Bremenmen, me. B J. Ae SCS 25, 1958, 324. Experimental investigation of a wing aerodynamics in the sleepstream. [...] Specific configuration of the experiment
I want to put each of them in every array dedicated to 5 arrays. I am having trouble in getting the title and the essence in an array position, can someone tell me what is wrong with this code? What I'm trying to do, read the text lines in the "x" and stop when it finds "A", when this happens, increase the position 1 to fill the next position
Try {collection = new file (file location); Fr = new FileReader (archive); Br = new buffed reader (FR); String numDoc = ""; Int pos = 0; While ((numDoc = br.readline ()) = null {{(numDoc.contains (". T")) {while ((numDoc = br.readline ())! = Null & amp; amp; In it (".a")) {title [pos] = title [pos] + numdoc; Status ++; }}}} Hold (exception e) {e.printStackTrace (); }
The goal is to get all the information in one line of the string. Any help would be greatly appreciated.
Running a code is always helpful In the future, you can probably use breakpoints, but I Looks like I know what I think is how I am getting a tap pointer exception.
while ((numDoc = br.readline ())! =) {If (numDoc.contains (".t")) {while ((numDoc = br.readline ()) ! = Null & amp; amp;! NumDoc.contains (".a")) { Outside, everything looks good, in this loop is that things start bunkers It seems.
title [pos] = title [pos] + numdoc;
With your given input, we will set:
Title [0]
as heading [0] + " This work of aerodynamics of experimental investigation "
occurs only when the title [0] is present, which I do not believe it has been initiated, You'll find out exactly one tap Array. It will either be a compiler error that is not being started or run-time null pointer is no exception. From the top of my head, I want to say compiler error.
Anyway, we will address the empty title [POS] to deal with.
while ((numdoc = Br.readline ())! = Null {if (numDoc.contains (".t")) {while ((numDoc = br.readline ())! = Null & amp; amp;; NumDoc.contains ("A") {if (title [pos]! = Null) {title [pos] = title [pos] + numdoc;} Else {title [pos] = numDoc ;} Pos ++;}}}
When we do another walkthrough, we will get the following array values
title [0] = one Experimental check of aerodynamics of
title [1] = Wing in a slipstream.
If this is the intention, then it is okay. If you want a title together , Then you move pos ++
into the loop.
while ((numDoc = br.readline ()) = null {if (numDoc.contains (".t")) {while ((numDoc = br.readline ())! = Null & amp;! NumDoc Add a location between the lines ([.a "]) {if (title [pos]! = Null) {title [pos] = title [pos] +" + numdoc; // lines {other} = NumDoc;}} POS ++;}}
Then we receive:
Title [0] = A wing aerodynamics in a slipstream Experimental investigation of
You can trim your input, but it will have to cover both potential errors that I can see.
Comments
Post a Comment