Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone!
I would like to know how you can put a matrix that came from c + + code in the Java console in an matrix in java. In fact, I send parameter to my c + + code from the java code, and the receipt of income is at the java console in the form of a text. so, I want to extract the matrix from the text .I need later in the code, I honestly do not know how.
below, this is my java code
OutputStream out = null;
     OutputStream err = null;
     PipedInputStream pipedInput = new PipedInputStream();
     PipedOutputStream pipedOutput = new PipedOutputStream(pipedInput);
     Program prog = new Program("C:\\Users\\abdelhalim\\Desktop\\ExempleMMKP33.exe", System.out, System.err, pipedInput);
        // TODO: Write pipedOutput from your favorite thread to send input to the program and finally close the stream.
        // I will use a PrintWriter because we are working here with text and not binary data.
        PrintWriter pw = new PrintWriter(pipedOutput);
        // println outputs platform specific newline but pw.print("5\n" ) would also convert "\n" to platform specific newline.
       res1= new int[n][m];
        for(int k=0; k<R.size();k++)
        for(int k=0; k<C.size();k++)
        for(int k=0; k<B.size();k++)
        for(int k=0; k<Dr.size();k++)
        for(int k=0; k<Dc.size();k++)
        for(int k=0; k<Db.size();k++)
        /*for(int k=0; k<n;k++)
      for(int j=0; j<m;j++)

and this is what I get in the java console:

0   0   0   0   1   0
   0   0   0   0   0   1
   0   1   0   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   1   0   0   0
propagators: 24
branchers:   1
runtime:      1.735 (1735.000 ms)
solutions:    48
propagations: 1715
nodes:        153
failures:     29
restarts:     0
peak depth:   7
peak memory:  13 KB

I want to put this matrix in a java code matrix (matrix type res1 = new int [n] [m]) after the reception and I do not know how to do it ??,,
you have an idea about that?? thank you very much for your help
Richard MacCutchan 1-Nov-13 14:22pm    
Read the text data and convert each field to integer and store in the matrix.
Manel1989 1-Nov-13 16:42pm    
thank you very much

1 solution

Read the console output as string and scan it. A space means end of integer, a new line a new row. You scans the string twice: first run to detect the dimensions and second run to read the values.

Very important: Implement robust error handling!!!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900