Java 尝试通过FTP上载文件时未找到Android文件异常
我正在尝试通过FTP将文本文件上载到服务器。文本文件位于data/data/my package/files中(我已签入DDMS)。我在LogCat中收到一个filenotfoundexception 这是我的密码:Java 尝试通过FTP上载文件时未找到Android文件异常,java,android,ftp,Java,Android,Ftp,我正在尝试通过FTP将文本文件上载到服务器。文本文件位于data/data/my package/files中(我已签入DDMS)。我在LogCat中收到一个filenotfoundexception 这是我的密码: FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect("82.163.99.80"); client.enterLocalPas
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();
}
}
有人能帮忙吗?您的代码:
fis = new FileInputStream(filename);
。。。需要路径,而不是文件名
请尝试:
fis = openFileInput(filename);
。。。它接受一个文件名并尝试在应用程序的私有文件存储区域中打开它。有关更多信息,请参阅《Android开发者数据存储指南》:,和。您尚未给出文件的确切路径。假设您在定义
FileInputStream
时遇到异常,这根本不是FTP问题。如果在传输过程中发生,则取决于您使用的FTP客户端。我怀疑是前者@ChintanRaghwani是对的,您应该指定文件的绝对路径。Chintan的道具和想法的基础,但我认为查找参考文献是值得赞扬的。:-)