2013-04-18 2 views
0

Apache Commons ftp 라이브러리를 사용하고 있으며 System.out.println()을 사용하여 파일 목록을 가져 왔지만 반환 된 파일 이름을 어떻게 ListView에로드 할 수 있습니까? 검색했지만 찾은 예제가 없습니다. 누구든지 ListView에서 FTP 파일을 보여주는 예가 있습니까?FtpClient.listFiles를 사용하여 ListView에 파일을 표시하는 예가 있습니까?

+0

참조 해주세요 [S/O 질문] [1] [1] : http://stackoverflow.com/questions/2576647/issue-with-org-apache- commons-net-ftp-ftpclient-listfiles 에는 도움이 될만한 예제가 들어 있습니다. –

+0

아니요. UI에는 그런 것이 없습니다. – RapsFan1981

+0

나는 그것을 실제로 알아 냈다. 파일 형식 아이콘으로 완료하십시오. 내 솔루션보기 – RapsFan1981

답변

0
liveToggle 
       .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
        public void onCheckedChanged(CompoundButton buttonView, 
          boolean isChecked) { 
         if (isChecked) { 
          directoryEntries.clear(); 

          FTPClient client = new FTPClient(); 

          try { 
           client.connect(address); 
           client.login(username, password); 

           // 
           // Obtain a list of filenames in the current 
           // working 
           // directory. When no file found an empty array 
           // will 
           // be returned. 
           // 
           String[] names = client.listNames(); 
           Drawable currentIcon = null; 
           for (String name : names) { 
            File tmpFile = new File(name); 
            String fileName = tmpFile.getName(); 
            if (checkEndsWithInStringArray(
              fileName, 
              getResources().getStringArray(
                R.array.fileEndingJs))) { 
             currentIcon = getResources() 
               .getDrawable(R.drawable.mimejs); 
            } else if (checkEndsWithInStringArray(
              fileName, 
              getResources().getStringArray(
                R.array.fileEndingHTML))) { 
             currentIcon = getResources() 
               .getDrawable(
                 R.drawable.mimehtml); 
            } else if (checkEndsWithInStringArray(
              fileName, 
              getResources().getStringArray(
                R.array.fileEndingCSS))) { 
             currentIcon = getResources() 
               .getDrawable(R.drawable.mimecss); 
            } else if (checkEndsWithInStringArray(
              fileName, 
              getResources().getStringArray(
                R.array.fileEndingXML))) { 
             currentIcon = getResources() 
               .getDrawable(R.drawable.mimexml); 
            } else if (checkEndsWithInStringArray(
              fileName, 
              getResources().getStringArray(
                R.array.fileEndingPhp))) { 
             currentIcon = getResources() 
               .getDrawable(R.drawable.mimephp); 
            } else { 
             currentIcon = getResources() 
               .getDrawable(R.drawable.mimetxt); 
            } 
            directoryEntries.add(new IconifiedText(
              tmpFile.getPath(), currentIcon)); 
            System.out.println("Name = " + name); 
           } 
           FTPFile[] ftpFiles = client.listFiles(); 
           for (FTPFile ftpFile : ftpFiles) { 
            // 
            // Check if FTPFile is a regular file 
            // 
            if (ftpFile.getType() == FTPFile.FILE_TYPE) { 
             System.out.println("FTPFile: " 
               + ftpFile.getName() 
               + "; " 
               + FileUtils 
                 .byteCountToDisplaySize(ftpFile 
                   .getSize())); 
            } 
           } 
           client.logout(); 
          } catch (IOException e) { 
           e.printStackTrace(); 
          } finally { 
           try { 
            client.disconnect(); 
           } catch (IOException e) { 
            e.printStackTrace(); 
           } 
          } 
         } 
        } 

       }); 
관련 문제