List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:com.panet.imeta.core.fileinput.FileInputList.java
public static FileInputList createFileList(VariableSpace space, String[] fileName, String[] fileMask, String[] fileRequired, boolean[] includeSubdirs, FileTypeFilter[] fileTypeFilters) { FileInputList fileInputList = new FileInputList(); // Replace possible environment variables... final String realfile[] = space.environmentSubstitute(fileName); final String realmask[] = space.environmentSubstitute(fileMask); for (int i = 0; i < realfile.length; i++) { final String onefile = realfile[i]; final String onemask = realmask[i]; final boolean onerequired = YES.equalsIgnoreCase(fileRequired[i]); final boolean subdirs = includeSubdirs[i]; final FileTypeFilter filter = ((fileTypeFilters == null || fileTypeFilters[i] == null) ? FileTypeFilter.ONLY_FILES : fileTypeFilters[i]);/*from www .j a v a 2 s . c o m*/ if (Const.isEmpty(onefile)) continue; // // If a wildcard is set we search for files // if (!Const.isEmpty(onemask)) { try { // Find all file names that match the wildcard in this directory // FileObject directoryFileObject = KettleVFS.getFileObject(onefile); if (directoryFileObject != null && directoryFileObject.getType() == FileType.FOLDER) // it's a directory { FileObject[] fileObjects = directoryFileObject.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return info.getDepth() == 0 || subdirs; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); try { if (fileObject != null && filter.isFileTypeAllowed(fileObject.getType())) { String name = fileObject.getName().getBaseName(); boolean matches = Pattern.matches(onemask, name); /* if (matches) { System.out.println("File match: URI: "+info.getFile()+", name="+name+", depth="+info.getDepth()); } */ return matches; } return false; } catch (FileSystemException ex) { // Upon error don't process the file. return false; } } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length; j++) { if (fileObjects[j].exists()) fileInputList.addFile(fileObjects[j]); } } if (Const.isEmpty(fileObjects)) { if (onerequired) fileInputList.addNonAccessibleFile(directoryFileObject); } // Sort the list: quicksort, only for regular files fileInputList.sortFiles(); } else { FileObject[] children = directoryFileObject.getChildren(); for (int j = 0; j < children.length; j++) { // See if the wildcard (regexp) matches... String name = children[j].getName().getBaseName(); if (Pattern.matches(onemask, name)) fileInputList.addFile(children[j]); } // We don't sort here, keep the order of the files in the archive. } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } else // A normal file... { try { FileObject fileObject = KettleVFS.getFileObject(onefile); if (fileObject.exists()) { if (fileObject.isReadable()) { fileInputList.addFile(fileObject); } else { if (onerequired) fileInputList.addNonAccessibleFile(fileObject); } } else { if (onerequired) fileInputList.addNonExistantFile(fileObject); } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } } return fileInputList; }
From source file:com.panet.imeta.job.entries.copyfiles.JobEntryCopyFiles.java
private boolean ProcessFileFolder(String sourcefilefoldername, String destinationfilefoldername, String wildcard, Job parentJob, Result result) { LogWriter log = LogWriter.getInstance(); boolean entrystatus = false; FileObject sourcefilefolder = null; FileObject destinationfilefolder = null; // Clear list files to remove after copy process // This list is also added to result files name list_files_remove.clear();//from ww w . j a va2 s.c o m list_add_result.clear(); // Get real source, destination file and wildcard String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername); String realDestinationFilefoldername = environmentSubstitute(destinationfilefoldername); String realWildcard = environmentSubstitute(wildcard); try { // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. System.gc(); sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername); destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername); if (sourcefilefolder.exists()) { // Check if destination folder/parent folder exists ! // If user wanted and if destination folder does not exist // PDI will create it if (CreateDestinationFolder(destinationfilefolder)) { // Basic Tests if (sourcefilefolder.getType().equals(FileType.FOLDER) && destination_is_a_file)// destinationfilefolder.getType().equals(FileType.FILE)) { // Source is a folder, destination is a file // WARNING !!! CAN NOT COPY FOLDER TO FILE !!! log.logError(Messages.getString("JobCopyFiles.Log.Forbidden"), Messages.getString("JobCopyFiles.Log.CanNotCopyFolderToFile", realSourceFilefoldername, realDestinationFilefoldername)); NbrFail++; } else { if (destinationfilefolder.getType().equals(FileType.FOLDER) && sourcefilefolder.getType().equals(FileType.FILE)) { // Source is a file, destination is a folder // Copy the file to the destination folder destinationfilefolder.copyFrom(sourcefilefolder.getParent(), new TextOneFileSelector(sourcefilefolder.getParent().toString(), sourcefilefolder.getName().getBaseName(), destinationfilefolder.toString())); if (log.isDetailed()) log.logDetailed(Messages.getString("JobCopyFiles.Log.FileCopiedInfos"), Messages.getString("JobCopyFiles.Log.FileCopied", sourcefilefolder.getName().toString(), destinationfilefolder.getName().toString())); } else if (sourcefilefolder.getType().equals(FileType.FILE) && destination_is_a_file) { // Source is a file, destination is a file destinationfilefolder.copyFrom(sourcefilefolder, new TextOneToOneFileSelector(destinationfilefolder)); } else { // Both source and destination are folders if (log.isDetailed()) { log.logDetailed("", " "); log.logDetailed(toString(), Messages.getString("JobCopyFiles.Log.FetchFolder", sourcefilefolder.toString())); } destinationfilefolder.copyFrom(sourcefilefolder, new TextFileSelector(sourcefilefolder.toString(), destinationfilefolder.toString(), realWildcard, parentJob)); } // Remove Files if needed if (remove_source_files && !list_files_remove.isEmpty()) { for (Iterator<String> iter = list_files_remove.iterator(); iter.hasNext() && !parentJob.isStopped();) { String fileremoventry = (String) iter.next(); // Remove ONLY Files if (KettleVFS.getFileObject(fileremoventry).getType() == FileType.FILE) { boolean deletefile = KettleVFS.getFileObject(fileremoventry).delete(); log.logBasic("", " ------ "); if (!deletefile) { log.logError(" " + Messages.getString("JobCopyFiles.Log.Error"), Messages.getString( "JobCopyFiles.Error.Exception.CanRemoveFileFolder", fileremoventry)); } else { if (log.isDetailed()) log.logDetailed( " " + Messages .getString("JobCopyFiles.Log.FileFolderRemovedInfos"), Messages.getString("JobCopyFiles.Log.FileFolderRemoved", fileremoventry)); } } } } // Add files to result files name if (add_result_filesname && !list_add_result.isEmpty()) { for (Iterator<String> iter = list_add_result.iterator(); iter.hasNext();) { String fileaddentry = (String) iter.next(); // Add ONLY Files if (KettleVFS.getFileObject(fileaddentry).getType() == FileType.FILE) { ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(fileaddentry), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); if (log.isDetailed()) { log.logDetailed("", " ------ "); log.logDetailed( " " + Messages.getString("JobCopyFiles.Log.ResultFilesName"), Messages.getString("JobCopyFiles.Log.FileAddedToResultFilesName", fileaddentry)); } } } } } entrystatus = true; } else { // Destination Folder or Parent folder is missing log.logError(toString(), Messages.getString("JobCopyFiles.Error.DestinationFolderNotFound", realDestinationFilefoldername)); } } else { log.logError(toString(), Messages.getString("JobCopyFiles.Error.SourceFileNotExists", realSourceFilefoldername)); } } catch (IOException e) { log.logError("Error", Messages.getString("JobCopyFiles.Error.Exception.CopyProcess", realSourceFilefoldername.toString(), destinationfilefolder.toString(), e.getMessage())); } finally { if (sourcefilefolder != null) { try { sourcefilefolder.close(); } catch (IOException ex) { } ; } if (destinationfilefolder != null) { try { destinationfilefolder.close(); } catch (IOException ex) { } ; } } return entrystatus; }
From source file:com.panet.imeta.job.entries.waitforfile.JobEntryWaitForFile.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; result.setResult(false);// ww w . j av a 2s . c o m // starttime (in seconds) long timeStart = System.currentTimeMillis() / 1000; if (filename != null) { FileObject fileObject = null; String realFilename = getRealFilename(); try { fileObject = KettleVFS.getFileObject(realFilename); long iMaximumTimeout = Const.toInt(getRealMaximumTimeout(), Const.toInt(DEFAULT_MAXIMUM_TIMEOUT, 0)); long iCycleTime = Const.toInt(getRealCheckCycleTime(), Const.toInt(DEFAULT_CHECK_CYCLE_TIME, 0)); // // Sanity check on some values, and complain on insanity // if (iMaximumTimeout < 0) { iMaximumTimeout = Const.toInt(DEFAULT_MAXIMUM_TIMEOUT, 0); if (log.isBasic()) log.logBasic(toString(), "Maximum timeout invalid, reset to " + iMaximumTimeout); } if (iCycleTime < 1) { // If lower than 1 set to the default iCycleTime = Const.toInt(DEFAULT_CHECK_CYCLE_TIME, 1); if (log.isBasic()) log.logBasic(toString(), "Check cycle time invalid, reset to " + iCycleTime); } if (iMaximumTimeout == 0) { if (log.isBasic()) log.logBasic(toString(), "Waiting indefinitely for file [" + realFilename + "]"); } else { if (log.isBasic()) log.logBasic(toString(), "Waiting " + iMaximumTimeout + " seconds for file [" + realFilename + "]"); } boolean continueLoop = true; while (continueLoop && !parentJob.isStopped()) { fileObject = KettleVFS.getFileObject(realFilename); if (fileObject.exists()) { // file exists, we're happy to exit if (log.isBasic()) log.logBasic(toString(), "Detected file [" + realFilename + "] within timeout"); result.setResult(true); continueLoop = false; // add filename to result filenames if (addFilenameToResult && fileObject.getType() == FileType.FILE) { ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, fileObject, parentJob.getJobname(), toString()); resultFile.setComment(Messages.getString("JobWaitForFile.FilenameAdded")); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); } } else { long now = System.currentTimeMillis() / 1000; if ((iMaximumTimeout > 0) && (now > (timeStart + iMaximumTimeout))) { continueLoop = false; // file doesn't exist after timeout, either true or // false if (isSuccessOnTimeout()) { if (log.isBasic()) log.logBasic(toString(), "Didn't detect file [" + realFilename + "] before timeout, success"); result.setResult(true); } else { if (log.isBasic()) log.logBasic(toString(), "Didn't detect file [" + realFilename + "] before timeout, failure"); result.setResult(false); } } // sleep algorithm long sleepTime = 0; if (iMaximumTimeout == 0) { sleepTime = iCycleTime; } else { if ((now + iCycleTime) < (timeStart + iMaximumTimeout)) { sleepTime = iCycleTime; } else { sleepTime = iCycleTime - ((now + iCycleTime) - (timeStart + iMaximumTimeout)); } } try { if (sleepTime > 0) { if (log.isDetailed()) { log.logDetailed(toString(), "Sleeping " + sleepTime + " seconds before next check for file [" + realFilename + "]"); } Thread.sleep(sleepTime * 1000); } } catch (InterruptedException e) { // something strange happened result.setResult(false); continueLoop = false; } } } if (!parentJob.isStopped() && fileObject.exists() && isFileSizeCheck()) { long oldSize = -1; long newSize = fileObject.getContent().getSize(); if (log.isDetailed()) log.logDetailed(toString(), "File [" + realFilename + "] is " + newSize + " bytes long"); if (log.isBasic()) log.logBasic(toString(), "Waiting until file [" + realFilename + "] stops growing for " + iCycleTime + " seconds"); while (oldSize != newSize && !parentJob.isStopped()) { try { if (log.isDetailed()) { log.logDetailed(toString(), "Sleeping " + iCycleTime + " seconds, waiting for file [" + realFilename + "] to stop growing"); } Thread.sleep(iCycleTime * 1000); } catch (InterruptedException e) { // something strange happened result.setResult(false); continueLoop = false; } oldSize = newSize; newSize = fileObject.getContent().getSize(); if (log.isDetailed()) { log.logDetailed(toString(), "File [" + realFilename + "] is " + newSize + " bytes long"); } } if (log.isBasic()) log.logBasic(toString(), "Stopped waiting for file [" + realFilename + "] to stop growing"); } if (parentJob.isStopped()) { result.setResult(false); } } catch (IOException e) { log.logBasic(toString(), "Exception while waiting for file [" + realFilename + "] to stop growing: " + e.getMessage()); } finally { if (fileObject != null) { try { fileObject.close(); } catch (Exception e) { } } } } else { log.logError(toString(), "No filename is defined."); } return result; }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean ProcessFileFolder(String sourcefilefoldername, String destinationfilefoldername, String wildcard, Job parentJob, Result result, String MoveToFolder, LogWriter log) { boolean entrystatus = false; FileObject sourcefilefolder = null; FileObject destinationfilefolder = null; FileObject movetofolderfolder = null; FileObject Currentfile = null; // Get real source, destination file and wildcard String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername); String realDestinationFilefoldername = environmentSubstitute(destinationfilefoldername); String realWildcard = environmentSubstitute(wildcard); try {//from w w w . ja v a 2 s.c om // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. System.gc(); sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername); destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername); if (!Const.isEmpty(MoveToFolder)) movetofolderfolder = KettleVFS.getFileObject(MoveToFolder); if (sourcefilefolder.exists()) { // Check if destination folder/parent folder exists ! // If user wanted and if destination folder does not exist // PDI will create it if (CreateDestinationFolder(destinationfilefolder)) { // Basic Tests if (sourcefilefolder.getType().equals(FileType.FOLDER) && destination_is_a_file) { // Source is a folder, destination is a file // WARNING !!! CAN NOT MOVE FOLDER TO FILE !!! log.logError(Messages.getString("JobMoveFiles.Log.Forbidden"), Messages.getString("JobMoveFiles.Log.CanNotMoveFolderToFile", realSourceFilefoldername, realDestinationFilefoldername)); // Update Errors updateErrors(); } else { if (destinationfilefolder.getType().equals(FileType.FOLDER) && sourcefilefolder.getType().equals(FileType.FILE)) { // Source is a file, destination is a folder // return destination short filename String shortfilename = sourcefilefolder.getName().getBaseName(); try { shortfilename = getDestinationFilename(sourcefilefolder.getName().getBaseName()); } catch (Exception e) { log.logError(toString(), Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename", sourcefilefolder.getName().getBaseName(), e.toString()))); return entrystatus; } // Move the file to the destination folder String destinationfilenamefull = destinationfilefolder.toString() + Const.FILE_SEPARATOR + shortfilename; FileObject destinationfile = KettleVFS.getFileObject(destinationfilenamefull); entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile, movetofolderfolder, log, parentJob, result); } else if (sourcefilefolder.getType().equals(FileType.FILE) && destination_is_a_file) { // Source is a file, destination is a file FileObject destinationfile = KettleVFS.getFileObject(realDestinationFilefoldername); // return destination short filename String shortfilename = destinationfile.getName().getBaseName(); try { shortfilename = getDestinationFilename(destinationfile.getName().getBaseName()); } catch (Exception e) { log.logError(toString(), Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename", sourcefilefolder.getName().getBaseName(), e.toString()))); return entrystatus; } String destinationfilenamefull = destinationfilefolder.getParent().toString() + Const.FILE_SEPARATOR + shortfilename; destinationfile = KettleVFS.getFileObject(destinationfilenamefull); entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile, movetofolderfolder, log, parentJob, result); } else { // Both source and destination are folders if (log.isDetailed()) { log.logDetailed(toString(), " "); log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FetchFolder", sourcefilefolder.toString())); } FileObject[] fileObjects = sourcefilefolder.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return true; } public boolean includeFile(FileSelectInfo info) { FileObject fileObject = info.getFile(); try { if (fileObject == null) return false; } catch (Exception ex) { // Upon error don't process the // file. return false; } finally { if (fileObject != null) { try { fileObject.close(); } catch (IOException ex) { } ; } } return true; } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) { // Success condition broken? if (successConditionBroken) { if (!successConditionBrokenExit) { log.logError(toString(), Messages.getString( "JobMoveFiles.Error.SuccessConditionbroken", "" + NrErrors)); successConditionBrokenExit = true; } return false; } // Fetch files in list one after one ... Currentfile = fileObjects[j]; if (!MoveOneFile(Currentfile, sourcefilefolder, realDestinationFilefoldername, realWildcard, log, parentJob, result, movetofolderfolder)) { // Update Errors updateErrors(); } } } } } entrystatus = true; } // end if else { // Destination Folder or Parent folder is missing log.logError(toString(), Messages.getString("JobMoveFiles.Error.DestinationFolderNotFound", realDestinationFilefoldername)); } } // end if else { log.logError(toString(), Messages.getString("JobMoveFiles.Error.SourceFileNotExists", realSourceFilefoldername)); } } // end try catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Error.Exception.MoveProcess", realSourceFilefoldername.toString(), destinationfilefolder.toString(), e.getMessage())); // Update Errors updateErrors(); } finally { if (sourcefilefolder != null) { try { sourcefilefolder.close(); } catch (IOException ex) { } ; } if (destinationfilefolder != null) { try { destinationfilefolder.close(); } catch (IOException ex) { } ; } if (Currentfile != null) { try { Currentfile.close(); } catch (IOException ex) { } ; } if (movetofolderfolder != null) { try { movetofolderfolder.close(); } catch (IOException ex) { } ; } } return entrystatus; }
From source file:be.ibridge.kettle.spoon.Spoon.java
private boolean saveTransXMLFile(TransMeta transMeta) { boolean saved = false; FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterExtensions(Const.STRING_TRANS_FILTER_EXT); dialog.setFilterNames(Const.getTransformationFilterNames()); String fname = dialog.open(); if (fname != null) { // Is the filename ending on .ktr, .xml? boolean ending = false; for (int i = 0; i < Const.STRING_TRANS_FILTER_EXT.length - 1; i++) { if (fname.endsWith(Const.STRING_TRANS_FILTER_EXT[i].substring(1))) { ending = true;//from ww w.j a v a2s .c om } } if (fname.endsWith(Const.STRING_TRANS_DEFAULT_EXT)) ending = true; if (!ending) { fname += Const.STRING_TRANS_DEFAULT_EXT; } // See if the file already exists... int id = SWT.YES; try { FileObject f = KettleVFS.getFileObject(fname); if (f.exists()) { MessageBox mb = new MessageBox(shell, SWT.NO | SWT.YES | SWT.ICON_WARNING); mb.setMessage(Messages.getString("Spoon.Dialog.PromptOverwriteFile.Message"));//"This file already exists. Do you want to overwrite it?" mb.setText(Messages.getString("Spoon.Dialog.PromptOverwriteFile.Title"));//"This file already exists!" id = mb.open(); } } catch (Exception e) { // TODO do we want to show an error dialog here? My first guess is not, but we might. } if (id == SWT.YES) { saved = save(transMeta, fname); transMeta.setFilename(fname); } } return saved; }
From source file:org.apache.carbondata.processing.csvreaderstep.CsvInputMeta.java
/** * Since the exported transformation that runs this will reside in a ZIP file, we can't * reference files relatively.//from w w w. j a v a 2 s .c om * So what this does is turn the name of files into absolute paths OR it simply includes the * resource in the ZIP file. * For now, we'll simply turn it into an absolute path and pray that the file is on a shared * drive or something like that. * HANDLER: create options to configure this behavior */ public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository) throws KettleException { try { // The object that we're modifying here is a copy of the original! // So let's change the filename from relative to absolute by grabbing the file object... // In case the name of the file comes from previous steps, forget about this! // if (Const.isEmpty(filenameField)) { // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.csv // To : /home/matt/test/files/foo/bar.csv // FileObject fileObject = KettleVFS.getFileObject(space.environmentSubstitute(filename), space); // If the file doesn't exist, forget about this effort too! // if (fileObject.exists()) { // Convert to an absolute path... // filename = resourceNamingInterface.nameResource(fileObject, space, true); return filename; } } return null; } catch (Exception e) { throw new KettleException(e); //$NON-NLS-1$ } }
From source file:org.apache.commons.vfs.example.Shell.java
/** * Does a 'cp' command./*from ww w . j a v a 2 s. c om*/ */ private void cp(final String[] cmd) throws Exception { if (cmd.length < 3) { throw new Exception("USAGE: cp <src> <dest>"); } final FileObject src = mgr.resolveFile(cwd, cmd[1]); FileObject dest = mgr.resolveFile(cwd, cmd[2]); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); }
From source file:org.apache.commons.vfs.example.Shell.java
/** * Does a 'cd' command.//from w w w . ja va 2 s . c o m * If the taget directory does not exist, a message is printed to <code>System.err</code>. */ private void cd(final String[] cmd) throws Exception { final String path; if (cmd.length > 1) { path = cmd[1]; } else { path = System.getProperty("user.home"); } // Locate and validate the folder FileObject tmp = mgr.resolveFile(cwd, path); if (tmp.exists()) { cwd = tmp; } else { System.out.println("Folder does not exist: " + tmp.getName()); } System.out.println("Current folder is " + cwd.getName()); }
From source file:org.apache.commons.vfs.example.Shell.java
/** * Does a 'touch' command.//from w w w . j a v a 2 s . c o m */ private void touch(final String[] cmd) throws Exception { if (cmd.length < 2) { throw new Exception("USAGE: touch <path>"); } final FileObject file = mgr.resolveFile(cwd, cmd[1]); if (!file.exists()) { file.createFile(); } file.getContent().setLastModifiedTime(System.currentTimeMillis()); }
From source file:org.apache.commons.vfs.example.ShowProperties.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs.example.ShowProperties LICENSE.txt"); return;/*from www .j a v a 2 s . co m*/ } for (int i = 0; i < args.length; i++) { try { FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + args[i]); FileObject file = mgr.resolveFile(args[i]); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }