我试图通过FTP将文本文件上传到服务器。文本文件位于data/data /我的包/文件中(我已经在DDMS中检查过)。我正在LogCat中获得filenotfoundexception。当试图通过FTP上传文件时发现Android文件异常
这里是我的代码:
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();
}
}
谁能帮助吗?
你还没有给出你的文件的确切路径。 – 2012-07-23 18:33:45
假设你在定义'FileInputStream'的地方得到异常,这根本不是FTP问题。如果在传输过程中发生这种情况,则取决于您使用的FTP客户端。我怀疑这是前者。 @ChintanRaghwani是正确的,你应该指定文件的绝对路径。 – Basic 2012-07-23 18:52:10