GeeCON Prague 2014*
The moose likes Java in General and the fly likes can not read file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "can not read file" Watch "can not read file" New topic
Author

can not read file

divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25
Hi all,

Im trying to read a file from a fileserver by setting up an ftp connection, where the path is passed as argument to the method. I have this following line to read the file from the given path, but it is throwing a null pointer exception.

in = new BufferedReader(new InputStreamReader(ftp.getInputStream(filepath, 0)));

where filepath is Fileserver\system\test\finals.txt

There is no problem with the ftp connection and the file exists in the location and its not empty.

Help me solve this issue.

Thanks,
Divya
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Just a wild guess, but what happens if you change the backslashes into forward slashes?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25
Hi,

I jus tried that..throws the same exception.
Chitti Ruddarraju
Greenhorn

Joined: Oct 19, 2009
Posts: 7
Try below example..

http://java.itags.org/java-newer/82796/
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Maybe it'd be easier if you told us what was actually null.
divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25
Hi all,

I could not test some of your suggestions as i ran into an other problem. I'm using SFTP to read files from the fileserver (not ftp. My apologies) and the license for using it expired. Now I have to replace sftp with ftp. I would like to know how do I replace sftp with ftp. The code to establish sftp connection is shown below.

import com.jscape.inet.sftp.*;
import com.jscape.inet.ssh.util.SshParameters;

public class SftpHandler {
public static final String SFTP_HOST = "aaa.org";
public static final String SFTP_USERID = "john";
public static final String SFTP_PASSWORD = "smith";


public SftpHandler() {
}

public static Sftp getSftpConnection() throws SftpException {

SshParameters params = new SshParameters(SFTP_HOST,SFTP_USERID,SFTP_PASSWORD);
Sftp sftp = new Sftp(params);
sftp.connect();
return sftp;
}

I would like to know how to use ftp just like sftp above, but Im quite unsure whether ftp is also licensed.

Thanks,
divyaa
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Read their documentation; back when I used it there were a few minor differences (which we fixed locally with a facade) but nothing major.

As to the license--maybe just check their website.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3016
    
  10
divya anand wrote:I have this following line to read the file from the given path, but it is throwing a null pointer exception.

in = new BufferedReader(new InputStreamReader(ftp.getInputStream(filepath, 0)));

Well, if that particular line is throwing the NPE (meaning that line is at the top of the stack trace, no other lines above it) then the variable "ftp" must be null at that point. Nothing else on that line could possibly throw an NPE. If you don't believe me, then try replacing it with:

You probably only need the first line - but this is an example of how you can debug a NullPointerException by figuring out exactly which thing is really null, as David suggests.
divya anand
Greenhorn

Joined: Oct 28, 2008
Posts: 25
Thanks David and Mike. I will try that.
 
 
subject: can not read file