开发者

Android: File listing of web server

开发者 https://www.devze.com 2023-04-10 02:02 出处:网络
I am trying to retrieve file listing from my (apache) http server via an android phone. Searched the web and forum without success. I was however able to do this in standard java using:

I am trying to retrieve file listing from my (apache) http server via an android phone. Searched the web and forum without success. I was however able to do this in standard java using:

package at.klp.serverlist;

import java.net.URL;
import java.util.List;
import org.apache.ivy.util.url.ApacheURLLister;

public class ServerFileListJava {

    public static void main(String[] args) {

        URL url1;
        List serverDir;

        try {           
            url1 = new URL("http://...url to server...");           
            ApacheURLLister lister1 = new ApacheURLLister();         
            serverDir = lister1.listAll(url1);
            System.out.println(serverDir);         
        } 

        catch (Exception e) {
            e.printStackTrace();
        }               

    }//end main
}//end class

Is a similar class available in Android, or can file listing somehow be done using org.apache.http*? I do not really want to use a WebView, or separate the html code using HttpGet and HttpResponse.

Thanks a lot for helping, any ideas?

Solved thanks to your answers. I imported ivy-2.0.0-rc1.jar into my project, did not know that this works! This video demonstrates how to import .jar`s into an Android project: http://www.youtube.com/watch?v=eY_uqi_qIz0&noredirect=1 th开发者_如何学运维anks!


ApacheURLLister is a pretty simple class with no special dependencies. You should have no problems copying it and use it directly in your code: https://svn.apache.org/repos/asf/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/ApacheURLLister.java


For Android Studio you can add Ivy on the build.gradle file

compile group: 'org.apache.ivy', name: 'ivy', version: '2.3.0'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号