List of usage examples for java.io File getPath
public String getPath()
From source file:PathInfo.java
public static void main(String[] args) throws IOException { File f = new File(args[0]); System.out.println("Absolute path = " + f.getAbsolutePath()); System.out.println("Canonical path = " + f.getCanonicalPath()); System.out.println("Name = " + f.getName()); System.out.println("Parent = " + f.getParent()); System.out.println("Path = " + f.getPath()); System.out.println("Absolute? = " + f.isAbsolute()); }
From source file:org.echocat.nodoodle.server.Main.java
public static void main(String[] args) { final File log4jConfig = new File(System.getProperty("log4j.configuration", "../config/log4j.xml")); if (log4jConfig.isFile()) { try {//w w w . ja va 2 s . co m final FileReader reader = new FileReader(log4jConfig); try { final DOMConfigurator domConfigurator = new DOMConfigurator(); domConfigurator.doConfigure(reader, getLoggerRepository()); } finally { IOUtils.closeQuietly(reader); } } catch (Exception e) { throw new RuntimeException("Could not configure log4j with " + log4jConfig + ".", e); } } final String applicationName = getApplicationName(); //System.setSecurityManager(new ServerSecurityManager()); LOG.info("Starting " + applicationName + "..."); final File config = new File( System.getProperty(Main.class.getPackage().getName() + ".config", "../config/nodoodleServer.xml")); final AbstractApplicationContext applicationContext = new FileSystemXmlApplicationContext(config.getPath()); LOG.info("Starting " + applicationName + "... DONE!"); Runtime.getRuntime().addShutdownHook(new Thread("destroyer") { @Override public void run() { LOG.info("Stopping " + applicationName + "..."); applicationContext.stop(); LOG.info("Stopping " + applicationName + "... DONE!"); } }); }
From source file:com.temenos.interaction.rimdsl.generator.launcher.Main.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();//from www .j a v a 2s. com OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetup().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.MainSpringPRD.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();//from w w w . j a v a2 s. c o m OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetupSpringPRD().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:com.ctriposs.rest4j.tools.data.FilterSchemaGenerator.java
public static void main(String[] args) { final CommandLineParser parser = new GnuParser(); CommandLine cl = null;//w ww . ja v a 2 s. c om try { cl = parser.parse(_options, args); } catch (ParseException e) { _log.error("Invalid arguments: " + e.getMessage()); reportInvalidArguments(); } final String[] directoryArgs = cl.getArgs(); if (directoryArgs.length != 2) { reportInvalidArguments(); } final File sourceDirectory = new File(directoryArgs[0]); if (!sourceDirectory.exists()) { _log.error(sourceDirectory.getPath() + " does not exist"); System.exit(1); } if (!sourceDirectory.isDirectory()) { _log.error(sourceDirectory.getPath() + " is not a directory"); System.exit(1); } final URI sourceDirectoryURI = sourceDirectory.toURI(); final File outputDirectory = new File(directoryArgs[1]); if (outputDirectory.exists() && !sourceDirectory.isDirectory()) { _log.error(outputDirectory.getPath() + " is not a directory"); System.exit(1); } final boolean isAvroMode = cl.hasOption('a'); final String predicateExpression = cl.getOptionValue('e'); final Predicate predicate = PredicateExpressionParser.parse(predicateExpression); final Collection<File> sourceFiles = FileUtil.listFiles(sourceDirectory, null); int exitCode = 0; for (File sourceFile : sourceFiles) { try { final ValidationOptions val = new ValidationOptions(); val.setAvroUnionMode(isAvroMode); final SchemaParser schemaParser = new SchemaParser(); schemaParser.setValidationOptions(val); schemaParser.parse(new FileInputStream(sourceFile)); if (schemaParser.hasError()) { _log.error("Error parsing " + sourceFile.getPath() + ": " + schemaParser.errorMessageBuilder().toString()); exitCode = 1; continue; } final DataSchema originalSchema = schemaParser.topLevelDataSchemas().get(0); if (!(originalSchema instanceof NamedDataSchema)) { _log.error(sourceFile.getPath() + " does not contain valid NamedDataSchema"); exitCode = 1; continue; } final SchemaParser filterParser = new SchemaParser(); filterParser.setValidationOptions(val); final NamedDataSchema filteredSchema = Filters.removeByPredicate((NamedDataSchema) originalSchema, predicate, filterParser); if (filterParser.hasError()) { _log.error("Error applying predicate: " + filterParser.errorMessageBuilder().toString()); exitCode = 1; continue; } final String relativePath = sourceDirectoryURI.relativize(sourceFile.toURI()).getPath(); final String outputFilePath = outputDirectory.getPath() + File.separator + relativePath; final File outputFile = new File(outputFilePath); final File outputFileParent = outputFile.getParentFile(); outputFileParent.mkdirs(); if (!outputFileParent.exists()) { _log.error("Unable to write filtered schema to " + outputFileParent.getPath()); exitCode = 1; continue; } FileOutputStream fout = new FileOutputStream(outputFile); fout.write(filteredSchema.toString().getBytes(RestConstants.DEFAULT_CHARSET)); fout.close(); } catch (IOException e) { _log.error(e.getMessage()); exitCode = 1; } } System.exit(exitCode); }
From source file:com.linkedin.restli.tools.data.FilterSchemaGenerator.java
public static void main(String[] args) { CommandLine cl = null;//from ww w.ja va 2 s. c o m try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(_options, args); } catch (ParseException e) { _log.error("Invalid arguments: " + e.getMessage()); reportInvalidArguments(); } final String[] directoryArgs = cl.getArgs(); if (directoryArgs.length != 2) { reportInvalidArguments(); } final File sourceDirectory = new File(directoryArgs[0]); if (!sourceDirectory.exists()) { _log.error(sourceDirectory.getPath() + " does not exist"); System.exit(1); } if (!sourceDirectory.isDirectory()) { _log.error(sourceDirectory.getPath() + " is not a directory"); System.exit(1); } final URI sourceDirectoryURI = sourceDirectory.toURI(); final File outputDirectory = new File(directoryArgs[1]); if (outputDirectory.exists() && !sourceDirectory.isDirectory()) { _log.error(outputDirectory.getPath() + " is not a directory"); System.exit(1); } final boolean isAvroMode = cl.hasOption('a'); final String predicateExpression = cl.getOptionValue('e'); final Predicate predicate = PredicateExpressionParser.parse(predicateExpression); final Collection<File> sourceFiles = FileUtil.listFiles(sourceDirectory, null); int exitCode = 0; for (File sourceFile : sourceFiles) { try { final ValidationOptions val = new ValidationOptions(); val.setAvroUnionMode(isAvroMode); final SchemaParser schemaParser = new SchemaParser(); schemaParser.setValidationOptions(val); schemaParser.parse(new FileInputStream(sourceFile)); if (schemaParser.hasError()) { _log.error("Error parsing " + sourceFile.getPath() + ": " + schemaParser.errorMessageBuilder()); exitCode = 1; continue; } final DataSchema originalSchema = schemaParser.topLevelDataSchemas().get(0); if (!(originalSchema instanceof NamedDataSchema)) { _log.error(sourceFile.getPath() + " does not contain valid NamedDataSchema"); exitCode = 1; continue; } final SchemaParser filterParser = new SchemaParser(); filterParser.setValidationOptions(val); final NamedDataSchema filteredSchema = Filters.removeByPredicate((NamedDataSchema) originalSchema, predicate, filterParser); if (filterParser.hasError()) { _log.error("Error applying predicate: " + filterParser.errorMessageBuilder()); exitCode = 1; continue; } final String relativePath = sourceDirectoryURI.relativize(sourceFile.toURI()).getPath(); final String outputFilePath = outputDirectory.getPath() + File.separator + relativePath; final File outputFile = new File(outputFilePath); final File outputFileParent = outputFile.getParentFile(); outputFileParent.mkdirs(); if (!outputFileParent.exists()) { _log.error("Unable to write filtered schema to " + outputFileParent.getPath()); exitCode = 1; continue; } FileOutputStream fout = new FileOutputStream(outputFile); String schemaJson = SchemaToJsonEncoder.schemaToJson(filteredSchema, JsonBuilder.Pretty.INDENTED); fout.write(schemaJson.getBytes(RestConstants.DEFAULT_CHARSET)); fout.close(); } catch (IOException e) { _log.error(e.getMessage()); exitCode = 1; } } System.exit(exitCode); }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test.txt"); boolean bool = f.exists(); // if path exists if (bool) {// w w w. ja va 2 s. c o m // returns the time file was last modified long millisec = f.lastModified(); // date and time Date dt = new Date(millisec); // path String path = f.getPath(); System.out.print(path + " last modified at: " + dt); } }
From source file:Main.java
public static void main(String[] args) { File file = new File(args[0]); if (!file.exists()) { System.out.println(args[0] + " does not exist."); return;//from ww w . j a v a 2 s . c om } if (file.isFile() && file.canRead()) { System.out.println(file.getName() + " can be read from."); } if (file.isDirectory()) { System.out.println(file.getPath() + " is a directory containing..."); String[] files = file.list(); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } } }
From source file:FileDemo.java
public static void main(String args[]) throws Exception { // Display constants System.out.println("pathSeparatorChar = " + File.pathSeparatorChar); System.out.println("separatorChar = " + File.separatorChar); // Test some methods File file = new File(args[0]); System.out.println("getName() = " + file.getName()); System.out.println("getParent() = " + file.getParent()); System.out.println("getAbsolutePath() = " + file.getAbsolutePath()); System.out.println("getCanonicalPath() = " + file.getCanonicalPath()); System.out.println("getPath() = " + file.getPath()); System.out.println("canRead() = " + file.canRead()); System.out.println("canWrite() = " + file.canWrite()); }
From source file:de.fosd.jdime.JDimeWrapper.java
public static void main(String[] args) throws IOException, InterruptedException { // setup logging Logger root = Logger.getLogger(JDimeWrapper.class.getPackage().getName()); root.setLevel(Level.WARNING); for (Handler handler : root.getHandlers()) { handler.setLevel(Level.WARNING); }/*ww w.j a va 2 s . c om*/ // setup JDime using the MergeContext MergeContext context = new MergeContext(); context.setPretend(true); context.setQuiet(false); // prepare the list of input files ArtifactList<FileArtifact> inputArtifacts = new ArtifactList<>(); for (String filename : args) { try { File file = new File(filename); // the revision name, this will be used as condition for ifdefs // as an example, I'll just use the filenames Revision rev = new Revision(FilenameUtils.getBaseName(file.getPath())); FileArtifact newArtifact = new FileArtifact(rev, file); inputArtifacts.add(newArtifact); } catch (FileNotFoundException e) { System.err.println("Input file not found: " + filename); } } context.setInputFiles(inputArtifacts); // setup strategies MergeStrategy<FileArtifact> structured = new StructuredStrategy(); MergeStrategy<FileArtifact> conditional = new NWayStrategy(); // run the merge first with structured strategy to see whether there are conflicts context.setMergeStrategy(structured); context.collectStatistics(true); Operation<FileArtifact> merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null, null, context.isConditionalMerge()); merge.apply(context); // if there are no conflicts, run the conditional strategy if (context.getStatistics().hasConflicts()) { context = new MergeContext(context); context.collectStatistics(false); context.setMergeStrategy(conditional); // use regular merging outside of methods context.setConditionalOutsideMethods(false); // we have to recreate the operation because now we will do a conditional merge merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null, null, context.isConditionalMerge()); merge.apply(context); } }