Fernando Carvalho
Fernando Carvalho

Reputation: 403

Accessing file in network with Java

I trying to access this file \192.168.1.1\d$\IISFolders\ftp\teste.png in my network to get his bytes and put in a json file and send. But to access this directory I need Authenticate..

json.replace( a.getImage()/*string no ads.getimage()*/, 
  new Base64Encode( "//192.168.1.1//d$//IISFolders//ftp//"+a.getImage() ).encode()/*base64 string image*/ );

/* The encode code - already tested works fine */
public String encode() throws IOException
{
    byte[] bytes = new byte[ 2048 ];
    byte[] result = new  byte[ (int) target.length() ];
    int ibytes;
    int counter = 0;

    while( ( ibytes = bis.read(bytes) ) != -1 ) /* Read from buffIn */
    {
        System.arraycopy(bytes, 0, result, counter, ibytes);
        counter += ibytes;
    }

    return new String( Base64.encodeBase64( result ) );
}

When I run the code the application couldn't find the file... throwing java.io.FileNotFoundException: \\192.168.1.1\d$\IISFolders\ftp\teste.png and (Username and/or password are wrong)...

How could I access this directory and his files?

Upvotes: 0

Views: 956

Answers (1)

JohnnyAW
JohnnyAW

Reputation: 2876

try this one:

FTPClient f = new FTPClient();
f.connect("//192.168.1.1//d$//IISFolders//ftp//");
f.login("foo", "bar");
InputStream is = retrieveFileStream(a.getImage());
...

look here for more information:FTPClient

Upvotes: 1

Related Questions