File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How can I print output of inputstream? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I print output of inputstream?" Watch "How can I print output of inputstream?" New topic

How can I print output of inputstream?

northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
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.*;
public class RuntimeFTP{
public static void main(String[] arg){
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "ftp.exe", "" };
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();

process = rt.exec(callAndArgs);
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!");

os = process.getOutputStream();
catch(IOException io)
System.out.println("io exception write to outputstream");

is = process.getInputStream();

while ( != -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

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: How can I print output of inputstream?
It's not a secret anymore!