c - java processbuilder open a text file for reading data -
i have file lets "test.txt", (same directory java program) has numbers on seen below. aim start process builder reads data file i'm going paint java jpanel.
i understand read data text file, need read input stream. question 1: how can read line line? after first line has read, process builder goes next?
i'm puzzled on how start process this. i.e q2: how can open text file using processbuilder?
for second question i've tried this. nothing happens on screen haven't instructed happen, on right track?
//get data public void returndata () { try { processbuilder pb; pb = new processbuilder("test.txt"); process runcode = pb.start(); runcode.waitfor(); } catch (ioexception | interruptedexception exp) { system.out.println(exp); } }
test.txt
0 1 3 5 2 3
you need program sends file standard out such windows:
type filename
for unix
cat filename
then execute command using processbuilder.
inputstreamreader read stream , bufferedreader read line line.
bufferedreader in = new bufferedreader(new inputstreamreader(processstream)); in.readline ();
this platform dependent way when basic java io in portable way.
filereader access file , bufferedreader read line line.
bufferedreader in = new bufferedreader(new filereader("foo.in")); in.readline ();
Comments
Post a Comment