text - Finding the first number of a .txt file - Java -
I have separate .txt
files, which should be read by java Then Java should give me the first number of the first line or if I say differently, the first number of the 4th word.
For example:
"AAAAAAA version 5.01"
or "AAAAAAA B version 6.0.2"
5 or 6 result must be a number.
I have tried some ways like bufferedReader with line.charAt, but I do not know how I can do it for my problem. What would you suggest?
BufferedReader br = null; Br = new BufferedReader (new FileReader (new file ("C: \\ user \\ desktop \\ new2.txt"))); String line = null; While ((line = br.readline ())! = Null {string [] parts = line.start (... ....); println ("");
First of all, just read the first line of the file.
file f = new file ("your_file .txt "); FileReader fr = New FileReader (f); Buffered Reader BR = New buffed reader (FR); String First First = br.readLine ();
Then the string array of words To get, split the line from the spaces
string [] word = First line lin split ("\\ s +");
"
string [] nos = words [3] .split (" \\ " . "). The system.out.println (number [0]); // expected output, the given file
Comments
Post a Comment