List of usage examples for java.io File getPath
public String getPath()
From source file:Main.java
public static void main(String[] args) { File f = new File("c:"); // true if the file path is a file, else false boolean bool = f.isFile(); // get the path String path = f.getPath(); System.out.println(path + " is file? " + bool); // create new file f = new File("c:/test.txt"); // true if the file path is a file, else false bool = f.isFile();/*from www . j a v a 2s. c om*/ // get the path path = f.getPath(); System.out.print(path + " is file? " + bool); }
From source file:Main.java
public static void main(String[] args) { File file = new File("/data"); if (file.isDirectory()) { String[] files = file.list(); if (files.length > 0) { System.out.println("The " + file.getPath() + " is not empty!"); }/*from w w w . j a va 2s . co m*/ } }
From source file:edu.birzeit.cs.parsers.TestParsingWithJSON.java
public static void main(String myHelpers[]) throws JSONException, IOException { File f = new File( "C:\\Users\\Bisan Co\\Documents\\NetBeansProjects\\WebApplication1\\src\\java/newjson.json"); String jsonString = readFile(f.getPath()); jsonOut = new JSONTokener(jsonString); JSONObject output = new JSONObject(jsonOut); String id = (String) output.getJSONObject("user1").get("-ID"); System.out.println(id);//from www . jav a 2 s . com String address = (String) output.getJSONObject("user2").getJSONObject("Friends").getJSONObject("friend1") .get("address"); System.out.println(address); }
From source file:org.duracloud.account.db.util.DbUtilDriver.java
public static void main(String[] args) throws IOException { if (args.length != 2) { usage("Two arguments are required, you supplied: " + args.length); System.exit(1);/*ww w . j ava2 s . c om*/ } DbUtil.COMMAND command = null; String commandArg = args[0]; if (commandArg.equalsIgnoreCase(DbUtil.COMMAND.PUT.name())) { command = DbUtil.COMMAND.PUT; } else { usage("The first argument must PUT. " + "The previously supported command GET and CLEAR " + "have been removed since the move to MC 2.0.0 " + "You supplied: " + commandArg); System.exit(1); } File workDir = new File(args[1]); if (!workDir.exists()) { usage("The work directory must exist: " + workDir.getPath()); System.exit(1); } else if (!workDir.isDirectory()) { usage("The work directory must be a directory: " + workDir.getPath()); System.exit(1); } ApplicationContext context = new ClassPathXmlApplicationContext("jpa-config.xml"); DuracloudRepoMgr repoMgr = context.getBean("repoMgr", DuracloudRepoMgr.class); DbUtil dbUtil = new DbUtil(repoMgr, workDir); dbUtil.runCommand(command); }
From source file:MainClass.java
public static void main(String[] args) { File absolute = new File("/public/html/javafaq/index.html"); File relative = new File("html/javafaq/index.html"); System.out.println("absolute: "); System.out.println(absolute.getName()); System.out.println(absolute.getPath()); System.out.println("relative: "); System.out.println(relative.getName()); System.out.println(relative.getPath()); }
From source file:Empty.java
public static void main(String[] argv) { if (argv.length != 1) { // no progname in argv[0] System.err.println("usage: Empty dirname"); System.exit(1);//ww w. j a va 2 s . c o m } File dir = new File(argv[0]); if (!dir.exists()) { System.out.println(argv[0] + " does not exist"); return; } String[] info = dir.list(); for (int i = 0; i < info.length; i++) { File n = new File(argv[0] + dir.separator + info[i]); if (!n.isFile()) // skip ., .., other directories too continue; System.out.println("removing " + n.getPath()); if (!n.delete()) System.err.println("Couldn't remove " + n.getPath()); } }
From source file:DirList.java
public static void main(String[] args) { System.out.print("\nEnter a path: "); String path = sc.nextLine();// w ww . j av a2 s . co m File dir = new File(path); if (!dir.exists() || !dir.isDirectory()) System.out.println("\nThat directory doesn't exist."); else { System.out.println("\nListing directory tree of:"); System.out.println(dir.getPath()); listDirectories(dir, " "); } }
From source file:FindDirectories.java
public static void main(String[] args) { // if no arguments provided, start at the parent directory if (args.length == 0) args = new String[] { ".." }; try {//from ww w . ja va 2 s. c om File pathName = new File(args[0]); String[] fileNames = pathName.list(); // enumerate all files in the directory for (int i = 0; i < fileNames.length; i++) { File f = new File(pathName.getPath(), fileNames[i]); // if the file is again a directory, call the main method recursively if (f.isDirectory()) { System.out.println(f.getCanonicalPath()); main(new String[] { f.getPath() }); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.iflytek.edu.cloud.frame.doc.BuildDocMain.java
public static void main(String[] args) throws Exception { ServiceDocBuilder docBuilder = new ServiceDocBuilder(); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); File jsonFile = getJsonFile(); JsonGenerator jsonGenerator = mapper.getFactory().createGenerator(jsonFile, JsonEncoding.UTF8); jsonGenerator.writeObject(docBuilder.buildDoc()); LOGGER.info("?API?" + jsonFile.getPath()); }
From source file:org.mzd.shap.spring.cli.ConfigSetup.java
public static void main(String[] args) { // check args if (args.length != 1) { exitOnError(1, null);//ww w. j ava 2 s. c om } // check file existance File analyzerXML = new File(args[0]); if (!analyzerXML.exists()) { exitOnError(1, "'" + analyzerXML.getPath() + "' did not exist\n"); } // prompt user whether existing data should be purged boolean isPurged = false; String ormContext = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("\nDo you wish to purge the database before running setup?"); System.out.println("WARNING: all existing data in SHAP will be lost!"); System.out.println("Really purge? yes/[NO]"); String ans = br.readLine(); if (ans.toLowerCase().equals("yes")) { System.out.println("Purging enabled"); ormContext = "orm-purge-context.xml"; isPurged = true; } else { System.out.println("Purging disabled"); ormContext = "orm-context.xml"; } } catch (IOException ex) { throw new RuntimeException(ex); } // run tool try { // Using a generic application context since we're referencing // both classpath and filesystem resources. GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("datasource-context.xml"), new ClassPathResource(ormContext), new FileSystemResource(analyzerXML)); ctx.refresh(); /* * Create an base admin user. */ if (isPurged) { //only attempted if we've wiped the old database. RoleDao roleDao = (RoleDao) ctx.getBean("roleDao"); Role adminRole = roleDao.saveOrUpdate(new Role("admin", "ROLE_ADMIN")); Role userRole = roleDao.saveOrUpdate(new Role("user", "ROLE_USER")); UserDao userDao = (UserDao) ctx.getBean("userDao"); userDao.saveOrUpdate(new User("admin", "admin", "shap01", adminRole, userRole)); } /* * Create some predefined analyzers. Users should have modified * the configuration file to suit their environment. */ AnnotatorDao annotatorDao = (AnnotatorDao) ctx.getBean("annotatorDao"); DetectorDao detectorDao = (DetectorDao) ctx.getBean("detectorDao"); ConfigSetup config = (ConfigSetup) ctx.getBean("configuration"); for (Annotator an : config.getAnnotators()) { System.out.println("Adding annotator: " + an.getName()); annotatorDao.saveOrUpdate(an); } for (Detector dt : config.getDetectors()) { System.out.println("Adding detector: " + dt.getName()); detectorDao.saveOrUpdate(dt); } System.exit(0); } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }