我试图将文件上载到与此代码的FTP服务器:上传文件到FTP服务器
private void upload(String ftpServer, String user, String password,
String fileName, File source) throws MalformedURLException,
IOException
{
if (ftpServer != null && fileName != null && source != null){
StringBuffer sb = new StringBuffer("ftp://");
if (user != null && password != null){
sb.append(user);
sb.append(':');
sb.append(password);
sb.append('@');
}
sb.append(ftpServer);
sb.append('/');
sb.append(fileName);
sb.append(";type=i");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL(sb.toString());
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true);
bos = new BufferedOutputStream(urlc.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(source));
int i;
while((i = bis.read()) != -1){
bos.write(i);
}
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
else{
Log.e("Tag", "Input not available.");
}
}
但文件没有在服务器上结束。
谢谢,我会试试。 – 2011-05-16 11:04:27