1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.example;
18
19 import java.text.DateFormat;
20 import java.util.Date;
21
22 import org.apache.commons.vfs2.FileObject;
23 import org.apache.commons.vfs2.FileSystemException;
24 import org.apache.commons.vfs2.FileSystemManager;
25 import org.apache.commons.vfs2.FileType;
26 import org.apache.commons.vfs2.VFS;
27
28
29
30
31 public final class ShowProperties {
32
33 private static final int SHOW_MAX = 5;
34
35 private ShowProperties() {
36
37 }
38
39 public static void main(final String[] args) {
40 if (args.length == 0) {
41 System.err.println("Please pass the name of a file as parameter.");
42 System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt");
43 return;
44 }
45 for (final String arg : args) {
46 try {
47 final FileSystemManager mgr = VFS.getManager();
48 System.out.println();
49 System.out.println("Parsing: " + arg);
50 final FileObject file = mgr.resolveFile(arg);
51 System.out.println("URL: " + file.getURL());
52 System.out.println("getName(): " + file.getName());
53 System.out.println("BaseName: " + file.getName().getBaseName());
54 System.out.println("Extension: " + file.getName().getExtension());
55 System.out.println("Path: " + file.getName().getPath());
56 System.out.println("Scheme: " + file.getName().getScheme());
57 System.out.println("URI: " + file.getName().getURI());
58 System.out.println("Root URI: " + file.getName().getRootURI());
59 System.out.println("Parent: " + file.getName().getParent());
60 System.out.println("Type: " + file.getType());
61 System.out.println("Exists: " + file.exists());
62 System.out.println("Readable: " + file.isReadable());
63 System.out.println("Writeable: " + file.isWriteable());
64 System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath());
65 if (file.exists()) {
66 if (file.getType().equals(FileType.FILE)) {
67 System.out.println("Size: " + file.getContent().getSize() + " bytes");
68 } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) {
69 final FileObject[] children = file.getChildren();
70 System.out.println("Directory with " + children.length + " files");
71 for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
72 System.out.println("#" + iterChildren + ": " + children[iterChildren].getName());
73 if (iterChildren > SHOW_MAX) {
74 break;
75 }
76 }
77 }
78 System.out.println("Last modified: "
79 + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())));
80 } else {
81 System.out.println("The file does not exist");
82 }
83 file.close();
84 } catch (final FileSystemException ex) {
85 ex.printStackTrace();
86 }
87 }
88 }
89
90 }