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.

  1. 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?

  2. 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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -