0
服务器我经历了许多讨论了有关从FTP上传文件server.I认为有2种方式来连接和上传:如何连接到FTP从Android的
1:我必须使用Apache库,并使用它的类像ftpclient。
2:像这样的代码的URLConnection:
public void getFile(URL u) throws IOException {
// url de type "http://www.monsite.com/monrep/mavideo.wmv"
String FileName = u.getFile();
FileName = FileName.substring(FileName.lastIndexOf('/') + 1);
URLConnection uc = u.openConnection();
int FileLenght = uc.getContentLength();
if (FileLenght == -1) {
monView2.setText("Fichier non valide:"+ FileName);
}
try
{
InputStream myInput = uc.getInputStream();
String outFileName = "/sdcard/GPTO/"+ NomParcours + "/" + FileName;
FileOutputStream myOutPut = new FileOutputStream(outFileName);
byte[]buff = new byte[1024];
int l = myInput.read(buff);
while(l>0)
{
myOutPut.write(buff, 0, l);
l = myInput.read(buff);
}
myOutPut.flush();
myOutPut.close();
}
catch(Exception e)
{
monView2.setText(e.toString());
}
}
请直接与我在正确的道路,我在Android的初学者,我知道刚才基础知识,什么是达到同样的路吗?
不硬编码sdcard路径'String outFileName =“/ sdcard'。使用'Environment'类获取有效路径 – 2013-04-05 08:23:30