• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I print output of inputstream?

 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please forgive me for running two similar thread but the other thread ahs strayed from primal concern of coding.
Some help with the code please???
I have set up an inputstream and outputstream to the "ftp process" of java.lang.Runtime I have sent the command "dir" to ftp.
But How can I get it to print all the files etc of the "dir" sent to ftp process?
Also I have just read that it is perhaps better to buffer the STREAMS.
How do I do this for outputsteam? I think I have some clue to do for inputstream with bufferedreader?
import java.lang.*;
import java.io.*;
public class RuntimeFTP{
public static void main(String[] arg){
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "ftp.exe", "jaguar.wmin.ac.uk" };
Process process = null;
OutputStream os = null;
InputStream is = null;

String login = "w0109699";
String password = "11041976";
String dircommand = "dir";
byte[] barraylogin = login.getBytes();
byte[] barraypassword = password.getBytes();
byte[] barraydircommand = dircommand.getBytes();

try
{
process = rt.exec(callAndArgs);
process.waitFor();
System.out.println("Process exit code is: " + process.exitValue() );
}
catch(IOException e)
{
System.err.println("IOException starting process!");
}
catch(InterruptedException e)
{
System.out.println("Interrupted waiting for process!");
}

try
{
os = process.getOutputStream();
os.write(barraylogin);
os.write(barraypassword);
os.write(barraydircommand);
}
catch(IOException io)
{
System.out.println("io exception write to outputstream");
}

try
{
is = process.getInputStream();

while (is.read() != -1)
{
/*

How can I print the data to the user
i.e all the data obtained from the "dir" command sent to ftp???

*/

}

}
catch(IOException io)
{
System.out.println("io exception read fron inputstream");
}



}
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code is often much easier to read and understand when it is formatted. You can preserve the formatting by surrounding the code with the [code] and [/code] UBB Tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic