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
36
37
38
39
40 public static void main(final String[] args) {
41 if (args.length == 0) {
42 System.err.println("Please pass the name of a file as parameter.");
43 System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt");
44 return;
45 }
46 for (final String arg : args) {
47 try {
48 final FileSystemManager mgr = VFS.getManager();
49 System.out.println();
50 System.out.println("Parsing: " + arg);
51 final FileObject file = mgr.resolveFile(arg);
52 System.out.println("URL: " + file.getURL());
53 System.out.println("getName(): " + file.getName());
54 System.out.println("BaseName: " + file.getName().getBaseName());
55 System.out.println("Extension: " + file.getName().getExtension());
56 System.out.println("Path: " + file.getName().getPath());
57 System.out.println("Scheme: " + file.getName().getScheme());
58 System.out.println("URI: " + file.getName().getURI());
59 System.out.println("Root URI: " + file.getName().getRootURI());
60 System.out.println("Parent: " + file.getName().getParent());
61 System.out.println("Type: " + file.getType());
62 System.out.println("Exists: " + file.exists());
63 System.out.println("Readable: " + file.isReadable());
64 System.out.println("Writeable: " + file.isWriteable());
65 System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath());
66 if (file.exists()) {
67 if (file.getType().equals(FileType.FILE)) {
68 System.out.println("Size: " + file.getContent().getSize() + " bytes");
69 } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) {
70 final FileObject[] children = file.getChildren();
71 System.out.println("Directory with " + children.length + " files");
72 for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
73 System.out.println("#" + iterChildren + ": " + children[iterChildren].getName());
74 if (iterChildren > SHOW_MAX) {
75 break;
76 }
77 }
78 }
79 System.out.println("Last modified: " + 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 private ShowProperties() {
91
92 }
93
94 }