java - hasNext and findInLine in Scanner Class using array -
i'm new java, have years experience in c, hope can me.
i have decimal file , need find header , there pick data , again header. lets file looks this:
480 124 125 001 047 001 047 001 480 001 001 001 001 001 001 001 001 001 001 001 001 047 001 480 002 002 002 002 002 002 002 002
my header is:
001 047 001 480
the header stored @ int array called "header".
i tried multiple ways- code:
integer i1 = new integer(this.header[0]); integer i2 = new integer(this.header[1]); integer i3 = new integer(this.header[2]); integer i4 = new integer(this.header[3]); nextdec.hasnext(i1.tostring() + i2.tostring() + i3.tostring() + i4.tostring());
returns false, though expect true. returns false if delete leading zeroes of header numbers in file (in reality can't delete them)
the code:
nextdec.findinline(i1.tostring() + " " + i2.tostring() + " " + i3.tostring() + " " + i4.tostring());
returns null, though expect return header. returns header if delete leading zeroes of header numbers in file why didn't work hasnext method?
the code:
nextdec.findinline(arrays.tostring(header));
has no output whatsoever, why that? how can detect header, leading zeroes, retrieve data , re-find it? possible find location (index) of header found?
thank you
i'll try clearer. have streaming data recorded on pc using monitor software. data logged file in decimal form leading zeroes (to have 3 digit numbers) , spaces between numbers. file contains multiple buffers. data buffer starts 4 byte header, need find in file header , collect data follows appropriate variables displayed in graph. thinking of using nextint, nextfloat according type of data want read after header found.
thank you
possible solution use header delimiter , scan input. think better do manually intead of using scanner.
import java.util.scanner; public class main { public static void main(string[] args) { string s = "480 124 125 001 047 001 047 001 480 001 001 001 001 001 001 001 001 001 001 001 001 047 001 480 002 002 002 002 002 002 002 002\n"; int header[] = new int[] {1, 47, 1, 480}; string stringheader = ""; (int e : header) { stringheader += string.format("%03d ", e); } scanner scanner = new scanner(s); scanner.usedelimiter(stringheader); // skipping before first header scanner.skip(".*?"+stringheader); // data between headers while(scanner.hasnext()) { system.out.println( scanner.next() ); } } }
output (two tokens after first , second header):
001 001 001 001 001 001 001 001 001 001 001 002 002 002 002 002 002 002 002
is want get?
Comments
Post a Comment