1 16 package org.apache.commons.vfs.example; 17 18 import org.apache.commons.vfs.FileObject; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.FileSystemManager; 21 import org.apache.commons.vfs.FileType; 22 import org.apache.commons.vfs.VFS; 23 24 import java.text.DateFormat ; 25 import java.util.Date ; 26 27 32 33 34 public class ShowProperties 35 { 36 public static void main(String [] args) 37 { 38 if (args.length == 0) 39 { 40 System.err.println("Please pass the name of a file as parameter."); 41 System.err.println("e.g. java org.apache.commons.vfs.example.ShowProperties LICENSE.txt"); 42 return; 43 } 44 for (int i = 0; i < args.length; i++) 45 { 46 try 47 { 48 FileSystemManager mgr = VFS.getManager(); 49 System.out.println(); 50 System.out.println("Parsing: " + args[i]); 51 FileObject file = mgr.resolveFile(args[i]); 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 { 68 if (file.getType().equals(FileType.FILE)) 69 { 70 System.out.println("Size: " + file.getContent().getSize() + " bytes"); 71 } 72 else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) 73 { 74 FileObject[] children = file.getChildren(); 75 System.out.println("Directory with " + children.length + " files"); 76 for (int iterChildren = 0; iterChildren < children.length; iterChildren++) 77 { 78 System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); 79 if (iterChildren > 5) 80 { 81 break; 82 } 83 } 84 } 85 System.out.println("Last modified: " + DateFormat.getInstance().format(new Date (file.getContent().getLastModifiedTime()))); 86 } 87 else 88 { 89 System.out.println("The file does not exist"); 90 } 91 file.close(); 92 } 93 catch (FileSystemException ex) 94 { 95 ex.printStackTrace(); 96 } 97 } 98 } 99 } 100 101 | Popular Tags |