使用Java访问网络中的文件

时间:2013-09-24 11:50:12

标签: java file ftp network-programming

我尝试在我的网络中访问此文件\ 192.168.1.1 \ d $ \ IISFolders \ ftp \ teste.png以获取其字节并放入json文件并发送。 但要访问此目录,我需要验证..

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 ) );
}

当我运行代码时,应用程序找不到文件...抛出java.io.FileNotFoundException: \\192.168.1.1\d$\IISFolders\ftp\teste.png和(用户名和/或密码错误)......

我如何访问此目录及其文件?

1 个答案:

答案 0 :(得分:1)

试试这个:

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

在此处查看更多信息:FTPClient