List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:edu.cornell.med.icb.goby.util.RenameWeights.java
public static void main(final String[] args) throws IOException { final File directory = new File("."); final String[] list = directory.list(new FilenameFilter() { public boolean accept(final File directory, final String filename) { final String extension = FilenameUtils.getExtension(filename); return (extension.equals("entries")); }/* w w w .j a v a 2 s .c o m*/ }); for (final String filename : args) { final String extension = FilenameUtils.getExtension(filename); final String basename = FilenameUtils.removeExtension(filename); for (final String alignFilename : list) { final String alignBasename = FilenameUtils.removeExtension(alignFilename); if (alignBasename.endsWith(basename)) { System.out.println("move " + filename + " to " + alignBasename + "." + extension); final File destination = new File(alignBasename + "." + extension); FileUtils.deleteQuietly(destination); FileUtils.moveFile(new File(filename), destination); } } } }
From source file:net.sf.jodreports.cli.CreateDocument.java
public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("USAGE: " + CreateDocument.class.getName() + " <template-document> <data-file> <output-document>"); System.exit(0);//from w w w .j a va 2 s. c o m } File templateFile = new File(args[0]); File dataFile = new File(args[1]); File outputFile = new File(args[2]); DocumentTemplateFactory documentTemplateFactory = new DocumentTemplateFactory(); DocumentTemplate template = documentTemplateFactory.getTemplate(templateFile); Object model = null; String dataFileExtension = FilenameUtils.getExtension(dataFile.getName()); if (dataFileExtension.equals("xml")) { model = NodeModel.parse(dataFile); } else if (dataFileExtension.equals("properties")) { Properties properties = new Properties(); properties.load(new FileInputStream(dataFile)); model = properties; } else { throw new IllegalArgumentException( "data file must be 'xml' or 'properties'; unsupported type: " + dataFileExtension); } template.createDocument(model, new FileOutputStream(outputFile)); }
From source file:listfiles.ListFiles.java
/** * @param args the command line arguments *///from ww w . j a v a2s . c o m public static void main(String[] args) { // TODO code application logic here BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String folderPath = ""; String fileName = "DirectoryFiles.xlsx"; try { System.out.println("Folder path :"); folderPath = reader.readLine(); //System.out.println("Output File Name :"); //fileName = reader.readLine(); XSSFWorkbook wb = new XSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream(folderPath + "\\" + fileName); XSSFSheet sheet1 = wb.createSheet("Files"); int row = 0; Stream<Path> stream = Files.walk(Paths.get(folderPath)); Iterator<Path> pathIt = stream.iterator(); String ext = ""; while (pathIt.hasNext()) { Path filePath = pathIt.next(); Cell cell1 = checkRowCellExists(sheet1, row, 0); Cell cell2 = checkRowCellExists(sheet1, row, 1); row++; ext = FilenameUtils.getExtension(filePath.getFileName().toString()); cell1.setCellValue(filePath.getFileName().toString()); cell2.setCellValue(ext); } sheet1.autoSizeColumn(0); sheet1.autoSizeColumn(1); wb.write(fileOut); fileOut.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("Program Finished"); }
From source file:edu.usf.cutr.siri.SiriParserJacksonExample.java
/** * Takes in a path to a JSON or XML file, parses the contents into a Siri object, * and prints out the contents of the Siri object. * // ww w .ja v a2s.c o m * @param args path to the JSON or XML file located on disk */ public static void main(String[] args) { if (args[0] == null) { System.out.println("Proper Usage is: java JacksonSiriParserExample path-to-siri-file-to-parse"); System.exit(0); } try { //Siri object we're going to instantiate based on JSON or XML data Siri siri = null; //Get example JSON or XML from file File file = new File(args[0]); System.out.println("Input file = " + file.getAbsolutePath()); /* * Alternately, instead of passing in a File, a String encoded in JSON or XML can be * passed into Jackson for parsing. Uncomment the below line to read the * JSON or XML into the String. */ //String inputExample = readFile(file); String extension = FilenameUtils.getExtension(args[0]); if (extension.equalsIgnoreCase("json")) { System.out.println("Parsing JSON..."); ObjectMapper mapper = null; try { mapper = (ObjectMapper) SiriUtils.readFromCache(SiriUtils.OBJECT_MAPPER); } catch (Exception e) { System.out.println("Error reading from cache: " + e); } if (mapper == null) { // instantiate ObjectMapper like normal if cache read failed mapper = new ObjectMapper(); //Jackson 2.0 configuration settings mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); mapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true); mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); //Tell Jackson to expect the JSON in PascalCase, instead of camelCase mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.PascalCaseStrategy()); } //Deserialize the JSON from the file into the Siri object siri = mapper.readValue(file, Siri.class); /* * Alternately, you can also deserialize the JSON from a String into the Siri object. * Uncomment the below line to parsing the JSON from a String instead of the File. */ //siri = mapper.readValue(inputExample, Siri.class); //Write the ObjectMapper to the cache, to speed up parsing for the next execution SiriUtils.forceCacheWrite(mapper); } if (extension.equalsIgnoreCase("xml")) { System.out.println("Parsing XML..."); //Use Aalto StAX implementation explicitly XmlFactory f = new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()); JacksonXmlModule module = new JacksonXmlModule(); /** * Tell Jackson that Lists are using "unwrapped" style (i.e., * there is no wrapper element for list). This fixes the error * "com.fasterxml.jackson.databind.JsonMappingException: Can not * >> instantiate value of type [simple type, class >> * uk.org.siri.siri.VehicleMonitoringDelivery] from JSON String; * no >> single-String constructor/factory method (through * reference chain: >> * uk.org.siri.siri.Siri["ServiceDelivery"]-> * uk.org.siri.siri.ServiceDel >> * ivery["VehicleMonitoringDelivery"])" * * NOTE - This requires Jackson v2.1 */ module.setDefaultUseWrapper(false); /** * Handles "xml:lang" attribute, which is used in SIRI * NaturalLanguage String, and looks like: <Description * xml:lang="EN">b/d 1:00pm until f/n. loc al and express buses * run w/delays & detours. POTUS visit in MANH. Allow additional * travel time Details at www.mta.info</Description> * * Passing "Value" (to match expected name in XML to map, * considering naming strategy) will make things work. This is * since JAXB uses pseudo-property name of "value" for XML Text * segments, whereas Jackson by default uses "" (to avoid name * collisions). * * NOTE - This requires Jackson v2.1 * * NOTE - This still requires a CustomPascalCaseStrategy to * work. Please see the CustomPascalCaseStrategy in this app * that is used below. */ module.setXMLTextElementName("Value"); XmlMapper xmlMapper = null; try { xmlMapper = (XmlMapper) SiriUtils.readFromCache(SiriUtils.XML_MAPPER); } catch (Exception e) { System.out.println("Error reading from cache: " + e); } if (xmlMapper == null) { xmlMapper = new XmlMapper(f, module); xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); xmlMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true); xmlMapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); /** * Tell Jackson to expect the XML in PascalCase, instead of camelCase * NOTE: We need the CustomPascalStrategy here to handle XML * namespace attributes such as xml:lang. See the comments in * CustomPascalStrategy for details. */ xmlMapper.setPropertyNamingStrategy(new CustomPascalCaseStrategy()); } //Parse the SIRI XML response siri = xmlMapper.readValue(file, Siri.class); //Write the XmlMapper to the cache, to speed up parsing for the next execution SiriUtils.forceCacheWrite(xmlMapper); } //If we successfully retrieved and parsed JSON or XML, print the contents if (siri != null) { SiriUtils.printContents(siri); } } catch (IOException e) { System.err.println("Error reading or parsing input file: " + e); } }
From source file:com.akana.demo.freemarker.templatetester.App.java
public static void main(String[] args) { final Options options = new Options(); @SuppressWarnings("static-access") Option optionContentType = OptionBuilder.withArgName("content-type").hasArg() .withDescription("content type of model").create("content"); @SuppressWarnings("static-access") Option optionUrlPath = OptionBuilder.withArgName("httpRequestLine").hasArg() .withDescription("url path and parameters in HTTP Request Line format").create("url"); @SuppressWarnings("static-access") Option optionRootMessageName = OptionBuilder.withArgName("messageName").hasArg() .withDescription("root data object name, defaults to 'message'").create("root"); @SuppressWarnings("static-access") Option optionAdditionalMessages = OptionBuilder.withArgName("dataModelPaths") .hasArgs(Option.UNLIMITED_VALUES).withDescription("additional message object data sources") .create("messages"); @SuppressWarnings("static-access") Option optionDebugMessages = OptionBuilder.hasArg(false) .withDescription("Shows debug information about template processing").create("debug"); Option optionHelp = new Option("help", "print this message"); options.addOption(optionHelp);/* w ww. j a va 2 s . co m*/ options.addOption(optionContentType); options.addOption(optionUrlPath); options.addOption(optionRootMessageName); options.addOption(optionAdditionalMessages); options.addOption(optionDebugMessages); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); // Check for help flag if (cmd.hasOption("help")) { showHelp(options); return; } String[] remainingArguments = cmd.getArgs(); if (remainingArguments.length < 2) { showHelp(options); return; } String ftlPath, dataPath = "none"; ftlPath = remainingArguments[0]; dataPath = remainingArguments[1]; String contentType = "text/xml"; // Discover content type from file extension String ext = FilenameUtils.getExtension(dataPath); if (ext.equals("json")) { contentType = "json"; } else if (ext.equals("txt")) { contentType = "txt"; } // Override discovered content type if (cmd.hasOption("content")) { contentType = cmd.getOptionValue("content"); } // Root data model name String rootMessageName = "message"; if (cmd.hasOption("root")) { rootMessageName = cmd.getOptionValue("root"); } // Additional data models String[] additionalModels = new String[0]; if (cmd.hasOption("messages")) { additionalModels = cmd.getOptionValues("messages"); } // Debug Info if (cmd.hasOption("debug")) { System.out.println(" Processing ftl : " + ftlPath); System.out.println(" with data model: " + dataPath); System.out.println(" with content-type: " + contentType); System.out.println(" data model object: " + rootMessageName); if (cmd.hasOption("messages")) { System.out.println("additional models: " + additionalModels.length); } } Configuration cfg = new Configuration(Configuration.VERSION_2_3_23); cfg.setDirectoryForTemplateLoading(new File(".")); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); /* Create the primary data-model */ Map<String, Object> message = new HashMap<String, Object>(); if (contentType.contains("json") || contentType.contains("txt")) { message.put("contentAsString", FileUtils.readFileToString(new File(dataPath), StandardCharsets.UTF_8)); } else { message.put("contentAsXml", freemarker.ext.dom.NodeModel.parse(new File(dataPath))); } if (cmd.hasOption("url")) { message.put("getProperty", new AkanaGetProperty(cmd.getOptionValue("url"))); } Map<String, Object> root = new HashMap<String, Object>(); root.put(rootMessageName, message); if (additionalModels.length > 0) { for (int i = 0; i < additionalModels.length; i++) { Map<String, Object> m = createMessageFromFile(additionalModels[i], contentType); root.put("message" + i, m); } } /* Get the template (uses cache internally) */ Template temp = cfg.getTemplate(ftlPath); /* Merge data-model with template */ Writer out = new OutputStreamWriter(System.out); temp.process(root, out); } catch (ParseException e) { showHelp(options); System.exit(1); } catch (IOException e) { System.out.println("Unable to parse ftl."); e.printStackTrace(); } catch (SAXException e) { System.out.println("XML parsing issue."); e.printStackTrace(); } catch (ParserConfigurationException e) { System.out.println("Unable to configure parser."); e.printStackTrace(); } catch (TemplateException e) { System.out.println("Unable to parse template."); e.printStackTrace(); } }
From source file:TestDumpRecord.java
public static void main(String[] args) throws NITFException { List<String> argList = Arrays.asList(args); List<File> files = new LinkedList<File>(); for (String arg : argList) { File f = new File(arg); if (f.isDirectory()) { File[] dirFiles = f.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { String ext = FilenameUtils.getExtension(name).toLowerCase(); return ext.matches("nitf|nsf|ntf"); }// www. ja v a 2 s . co m }); files.addAll(Arrays.asList(dirFiles)); } else files.add(f); } Reader reader = new Reader(); for (File file : files) { PrintStream out = System.out; out.println("=== " + file.getAbsolutePath() + " ==="); IOHandle handle = new IOHandle(file.getAbsolutePath()); Record record = reader.read(handle); dumpRecord(record, reader, out); handle.close(); record.destruct(); // tells the memory manager to decrement the ref // count } }
From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);//from ww w . j a v a 2s .c om CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); if (line.hasOption("file") && line.hasOption("folder")) { System.err.println("Can not use both -file and -folder on the command line at the same time."); System.exit(-1); } //if (line.hasOption("file") && line.hasOption("folder")) if (line.hasOption("download")) { if (line.hasOption("folder")) { String localFolder = FilenameUtils.normalize(line.getOptionValue("folder")); String containerName = null; if (StringUtils.isNotBlank(localFolder)) { File localFolderObj = new File(localFolder); if (localFolderObj.exists() && localFolderObj.isDirectory()) { if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println( "You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(ontainerName)) } else { System.err.println( "You must provide the -container for a copy operation to work as expected."); System.exit(-1); } System.out.println("Downloading all objects from: " + containerName + " to local folder: " + localFolder); getContainerObjects(localFolderObj, containerName); } else { if (!localFolderObj.exists()) { System.err.println("The local folder: " + localFolder + " does not exist. Create it first and then run this command."); } if (!localFolderObj.isDirectory()) { System.err.println( "The local folder name supplied : " + localFolder + " is not a folder !"); } System.exit(-1); } } } System.exit(0); } //if (line.hasOption("download")) if (line.hasOption("folder")) { String containerName = null; String folderPath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } folderPath = line.getOptionValue("folder"); if (StringUtils.isNotBlank(folderPath)) { File folder = new File(FilenameUtils.normalize(folderPath)); if (folder.isDirectory()) { if (line.hasOption("z")) { System.out.println("Zipping: " + folderPath); System.out.println("Nested folders are ignored !"); File zipedFolder = zipFolder(folder); String mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName); } else { File[] files = folder.listFiles(); for (File f : files) { String mimeType = FilesConstants .getMimetype(FilenameUtils.getExtension(f.getName())); System.out.println("Uploading :" + f.getName() + " to " + folder.getName()); copyToCreateContainerIfNeeded(f, mimeType, containerName); System.out.println( "Upload :" + f.getName() + " to " + folder.getName() + " completed."); } } } else { System.err.println("You must provide a valid folder value for the -folder option !"); System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath)); System.exit(-1); } } } //if (line.hasOption("folder")) if (line.hasOption("file")) { String containerName = null; String fileNamePath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } fileNamePath = line.getOptionValue("file"); if (StringUtils.isNotBlank(fileNamePath)) { String fileName = FilenameUtils.normalize(fileNamePath); String fileExt = FilenameUtils.getExtension(fileNamePath); String mimeType = FilesConstants.getMimetype(fileExt); File file = new File(fileName); if (line.hasOption("z")) { logger.info("Zipping " + fileName); if (!file.isDirectory()) { File zippedFile = zipFile(file); mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyTo(zippedFile, mimeType, containerName); zippedFile.delete(); } } //if (line.hasOption("z")) else { logger.info("Uploading " + fileName + "."); if (!file.isDirectory()) copyTo(file, mimeType, containerName); else { System.err.println( "The path you provided is a folder. For uploading folders use the -folder option."); System.exit(-1); } } } //if (StringUtils.isNotBlank(file)) else { System.err.println("You must provide a valid value for the file to upload !"); System.exit(-1); } } //if (line.hasOption("file")) } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (FilesAuthorizationException err) { logger.fatal("FilesAuthorizationException : Failed to login to your account !" + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch (FilesAuthorizationException err) catch (IOException err) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesCopy.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*from w ww .j a v a 2s . c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); if (line.hasOption("file") && line.hasOption("folder")) { System.err.println("Can not use both -file and -folder on the command line at the same time."); System.exit(-1); } //if (line.hasOption("file") && line.hasOption("folder")) if (line.hasOption("download")) { if (line.hasOption("folder")) { String localFolder = FilenameUtils.normalize(line.getOptionValue("folder")); String containerName = null; if (StringUtils.isNotBlank(localFolder)) { File localFolderObj = new File(localFolder); if (localFolderObj.exists() && localFolderObj.isDirectory()) { if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println( "You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(ontainerName)) } else { System.err.println( "You must provide the -container for a copy operation to work as expected."); System.exit(-1); } System.out.println("Downloading all objects from: " + containerName + " to local folder: " + localFolder); getContainerObjects(localFolderObj, containerName); } else { if (!localFolderObj.exists()) { System.err.println("The local folder: " + localFolder + " does not exist. Create it first and then run this command."); } if (!localFolderObj.isDirectory()) { System.err.println( "The local folder name supplied : " + localFolder + " is not a folder !"); } System.exit(-1); } } } System.exit(0); } //if (line.hasOption("download")) if (line.hasOption("folder")) { String containerName = null; String folderPath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } folderPath = line.getOptionValue("folder"); if (StringUtils.isNotBlank(folderPath)) { File folder = new File(FilenameUtils.normalize(folderPath)); if (folder.isDirectory()) { if (line.hasOption("z")) { System.out.println("Zipping: " + folderPath); System.out.println("Nested folders are ignored !"); File zipedFolder = zipFolder(folder); String mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName); } else { File[] files = folder.listFiles(); for (File f : files) { String mimeType = FilesConstants .getMimetype(FilenameUtils.getExtension(f.getName())); System.out.println("Uploading :" + f.getName() + " to " + folder.getName()); copyToCreateContainerIfNeeded(f, mimeType, containerName); System.out.println( "Upload :" + f.getName() + " to " + folder.getName() + " completed."); } } } else { System.err.println("You must provide a valid folder value for the -folder option !"); System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath)); System.exit(-1); } } } //if (line.hasOption("folder")) if (line.hasOption("file")) { String containerName = null; String fileNamePath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } fileNamePath = line.getOptionValue("file"); if (StringUtils.isNotBlank(fileNamePath)) { String fileName = FilenameUtils.normalize(fileNamePath); String fileExt = FilenameUtils.getExtension(fileNamePath); String mimeType = FilesConstants.getMimetype(fileExt); File file = new File(fileName); if (line.hasOption("z")) { logger.info("Zipping " + fileName); if (!file.isDirectory()) { File zippedFile = zipFile(file); mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyTo(zippedFile, mimeType, containerName); zippedFile.delete(); } } //if (line.hasOption("z")) else { logger.info("Uploading " + fileName + "."); if (!file.isDirectory()) copyTo(file, mimeType, containerName); else { System.err.println( "The path you provided is a folder. For uploading folders use the -folder option."); System.exit(-1); } } } //if (StringUtils.isNotBlank(file)) else { System.err.println("You must provide a valid value for the file to upload !"); System.exit(-1); } } //if (line.hasOption("file")) } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (FilesAuthorizationException err) { logger.fatal("FilesAuthorizationException : Failed to login to your account !" + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch (FilesAuthorizationException err) catch (Exception err) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.telecel.utils.FileUtils.java
public static String getExtension(File file) { String ext; ext = FilenameUtils.getExtension(file.getAbsolutePath()); return ext; }
From source file:andrew.addons.NextFile.java
public static String nextFile(String filename) { int a = 1;//from w ww.ja va2 s . c o m File file = new File(filename); while (file.exists() || file.isFile()) { file = new File(FilenameUtils.removeExtension(filename) + "(" + Integer.toString(a) + ")." + FilenameUtils.getExtension(filename)); a++; } return file.getName(); }