-1

I'm trying to upload a text file to a server via FTP. The text file is in data/data/my package/files (I have checked in the DDMS). I am getting a filenotfoundexception in LogCat.

Here's my code:

FTPClient client = new FTPClient();
     FileInputStream fis = null;

   try {
     client.connect("82.163.99.80");
     client.enterLocalPassiveMode();
     client.login("user", "password");

     //
     // Create an InputStream of the file to be uploaded
     //
     String filename = "sdcardstats.txt";
     fis = new FileInputStream(filename);

     //
     // Store file to server
     //
     client.storeFile(filename, fis);
     client.logout();
 } catch (IOException e) {
     e.printStackTrace();
 } finally {
     try {
         if (fis != null) {
             fis.close();
         }
         client.disconnect();
     } catch (IOException e) {
         e.printStackTrace();
     }
     }

Can anyone help please?

4

1 回答 1

1

你的代码:

fis = new FileInputStream(filename);

... 需要路径,而不是文件名。

请尝试:

fis = openFileInput(filename);

...它采用文件名并尝试在应用程序的私有文件存储区域中打开它。有关更多信息,请参阅数据存储的 Android 开发人员指南:内部文件,以及FileInputStreamopenFileInput

于 2012-07-23T18:56:23.490 回答