0

FTPサーバーからファイルをアップロードすることについて多くの議論を経てきました.接続してアップロードするには2つの方法があると思います:

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 の初心者で、基本的なことしか知りません。同じことを達成する正しい方法は何ですか?

4

1 に答える 1