how to read the file from ftp server

Hi

I need to read a file from a ftp server . Iam using apache lib common-net .jar .

FTPClient ftp = new FTPClient();

ftp.connect(server);

ftp.login(username,password);

FTPFile[] files = ftp.listFiles();

for(int i=0 ;i<files.length;i++){

System.out.println(" File : "+ i + " - " + files);

}

InputStream ip = ftp.retrieveFileStream(path);

I got the inputstream from the ftp server. but iam not able to read the contents of the file ....

help me plzzzzz>

[540 byte] By [mnrnjn_ranjana] at [2007-11-27 6:34:11]
# 1
> but iam not able to read the contents of the file ....Why not? What happens?
quittea at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...
# 2
HiThanks for ur reply Iam only able to read in bytes i.e inputstream.read(); but iam not able to read it as a string values........
mnrnjn_ranjana at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...
# 3
> but iam not able to read it as a string values........Wrap an InputStreamReader around the InputStream and give the correct charset name. Maybe wrap a BufferedReader around the InputStreamReader for more efficiency and comfort.
quittea at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi Can u tell me how to Wrap an InputStreamReader around the InputStream and give the correct charset name...plzzzzzz
mnrnjn_ranjana at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...
# 5
Hii got it ........thanks for u reply
mnrnjn_ranjana at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...
# 6

Hi

I have one more problem . first i try to read the file and write the file in local directory . then i try to read the data in the remote file .. iam getting the datas as null.

InputStream ip = ftp.retrieveFileStream(path);

File f = new File("D:\\ftp.txt");

FileOutputStream fo = new FileOutputStream(f);

byte[] buf = new byte[1024];

while ((len = ip.read(buf)) > 0) {

fo.write(buf,0,len);

}

fo.close();

BufferedReader br = new BufferedReader(new InputStreamReader(ip));

String line;

do {

line = br.readLine();

System.out.println(" data " +line);

}while (line != null);

mnrnjn_ranjana at 2007-7-12 18:00:28 > top of Java-index,Java Essentials,Java Programming...