我用 sun.net.ftp.* 这个包中的 list() 函数显示出了ftp服务器中的文件目录,但是怎样区分哪些东西是文件,哪些东西又是目录呢?我的方法如下: jList list=new jList();
DefaultListModel model = new DefaultListModel();
in = new BufferedReader(new InputStreamReader(ftp.list()));
String line = null;
while ((line = in.readLine()) != null) {
model.addElement(line.substring(0));
}
list.setModel(model);
DefaultListModel model = new DefaultListModel();
in = new BufferedReader(new InputStreamReader(ftp.list()));
String line = null;
while ((line = in.readLine()) != null) {
model.addElement(line.substring(0));
}
list.setModel(model);
public boolean isDirectory()
Tests whether the file denoted by this abstract pathname is a directory. Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise isFile
public boolean isFile()
Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file. Returns:
true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise
-rw-rw-r-- 1 keiy other 14 Dec 2 2003 1
-rw-rw-r-- 1 keiy other 54 Dec 2 2003 t.c
-rw-rw-r-- 1 keiy other 69 Dec 2 2003 t1
-rw-rw-r-- 1 keiy other 69 Dec 2 2003 t2
drwxrwxr-x 2 keiy other 4096 Aug 6 18:05 ttt
只要判行首的第一个字母就可以了(d为目录)
----------------------------------------------
我从不用windwos的ftp,所以windwos你可看一下,估计有类似返回(或windows目录格式,也可用<DIR>来判)
http://www.novell.com/documentation//nw5/docui/index.html#../usprint/unixpenu/data/hpyvrshh.html^h1ef7fx1