Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can not read file

 
divya anand
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a wild guess, but what happens if you change the backslashes into forward slashes?
 
divya anand
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I jus tried that..throws the same exception.
 
Chitti Ruddarraju
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try below example..

http://java.itags.org/java-newer/82796/
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it'd be easier if you told us what was actually null.
 
divya anand
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3078
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David and Mike. I will try that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic