List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:com.elevenpaths.googleindexretriever.GoogleSearch.java
public void saveSpamKeywords() throws IOException { File file = new File("spamKeywords.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile();/*from www. jav a 2 s . c o m*/ } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); for (String k : keywordsSpam) { bw.write(k); bw.newLine(); } bw.close(); fw.close(); }
From source file:MonitorSaurausRex.MainMenu.java
private boolean anyEncFileExists(File[] listOfFilesAndFolders) { for (File file : listOfFilesAndFolders) { String filePath = file.getAbsoluteFile().toString(); if (!file.isDirectory() && filePath.substring(filePath.length() - 4, filePath.length()).equals(".enc")) { System.out.println(file.getAbsoluteFile() + " is already encrypted"); Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null, "1 or more files are already encrypted !! \nPlease de-select them."); return true; }/*from w ww . j a va2 s . co m*/ } return false; }
From source file:MonitorSaurausRex.MainMenu.java
private boolean allAreEncFiles(File[] listOfFilesAndFolders) { for (File file : listOfFilesAndFolders) { String filePath = file.getAbsoluteFile().toString(); if (!file.isDirectory() && !filePath.substring(filePath.length() - 4, filePath.length()).equals(".enc")) { System.out.println(file.getAbsoluteFile() + " is not encrypted"); Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null, "1 or more files are not encrypted !! \nPlease de-select them."); return false; }/* w w w . j av a 2 s .co m*/ } return false; }
From source file:com.sangupta.clitools.file.Trim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.strip(line, null); contents.set(index, line);//from w ww. j a va 2 s .co m } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:com.quartzdesk.executor.web.spring.SpringProfilesActivator.java
/** * Merges properties from the {@code default-quartzdesk-executor.properties} and * <code>${quartzdesk-executor.work.dir}/quartzdesk-executor.properties</code> (if it exists) and returns the value * of the {@code db.profile.name} configuration property. * * @param workDir the QuartzDesk Executor work directory. * @return the database profile to activate. *///from w w w.j a v a2 s. co m private String getDatabaseProfile(WorkDir workDir) { Properties mergedCfg = new Properties(); /* * 1. read default-quartzdesk-executor.properties */ InputStream defaultCfgIns = null; try { defaultCfgIns = CommonUtils.getResourceAsStream(DEFAULT_QUARTZDESK_EXECUTOR_CFG); if (defaultCfgIns == null) throw new ApplicationContextException("Default QuartzDesk Executor configuration: " + DEFAULT_QUARTZDESK_EXECUTOR_CFG + " not found."); Properties defaultCfg = new Properties(); defaultCfg.load(defaultCfgIns); mergedCfg.putAll(defaultCfg); } catch (IOException e) { throw new ApplicationContextException( "Error reading default QuartzDesk Executor configuration: " + DEFAULT_QUARTZDESK_EXECUTOR_CFG, e); } finally { IOUtils.close(defaultCfgIns); } /* * 2. read ${quartzdesk-executor.work.dir}/quartzdesk-executor.properties */ File cfgFile = new File(workDir.getRoot(), "quartzdesk-executor.properties"); if (IOUtils.isReadableFile(cfgFile)) { InputStream cfgIns = null; try { cfgIns = new FileInputStream(cfgFile); Properties cfg = new Properties(); cfg.load(cfgIns); mergedCfg.putAll(cfg); } catch (IOException e) { throw new ApplicationContextException( "Error reading QuartzDesk configuration: " + cfgFile.getAbsoluteFile(), e); } finally { IOUtils.close(cfgIns); } } String dbProfile = mergedCfg.getProperty(CONFIG_KEY_DB_PROFILE); if (dbProfile == null) { throw new ApplicationContextException( "QuartzDesk Executor configuration property: " + CONFIG_KEY_DB_PROFILE + " not defined."); } return dbProfile.trim(); }
From source file:com.elevenpaths.googleindexretriever.GoogleSearch.java
public void export(ArrayList<ArrayList<String>> data, String dork, String nameFile) throws IOException { File file = new File(nameFile); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile();//w w w. j a v a 2 s .c om } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write( "<style type=\"text/css\"> table.sample { border-width: 1px; border-spacing: 2px; border-style: outset; border-color: black; border-collapse: separate; background-color: white; } table.sample th { border-width: 1px; padding: 5px; border-style: inset; border-color: green; background-color: white; } table.sample td { border-width: 1px; padding: 5px; border-style: inset; border-color: green; background-color: white; }</style>"); bw.newLine(); bw.write("<h1>#Dork: <font color=blue>" + dork + "</font><br>#Total: <font color=blue>" + data.size() + "</font></h1>"); bw.write( "<table class=sample><tr><td><font color=blue>Words</font></td><td><font color=blue>Sentences</font></td></tr>");// Start table for (ArrayList<String> ds : data) { bw.write("<tr>"); for (String row : ds) { if (!row.isEmpty()) { bw.write("<td>" + escapeHtml4(row) + "</td>"); bw.newLine(); } } bw.write("</tr>"); } bw.write("</table>"); bw.close(); fw.close(); }
From source file:com.sangupta.clitools.file.RightTrim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.stripEnd(line, null); contents.set(index, line);//from w ww. j a v a 2 s . co m } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " right-trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:com.sangupta.clitools.file.LeftTrim.java
@Override protected boolean processFile(File file) throws IOException { // read entire file in memory List<String> contents = FileUtils.readLines(file); final long initial = file.length(); // now for each string - trim from end for (int index = 0; index < contents.size(); index++) { String line = contents.get(index); line = StringUtils.stripStart(line, null); contents.set(index, line);/*from w ww . j a va2s . c o m*/ } // write back contents of file FileUtils.writeLines(file, contents); long current = file.length(); this.bytesSaved.addAndGet(initial - current); System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " left-trimmed and saved " + (initial - current) + " bytes."); return true; }
From source file:helma.main.ApplicationManager.java
private File getAbsoluteFile(String path) { // make sure our directory has an absolute path, // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4117557 File file = new File(path); if (file.isAbsolute()) { return file; } else {//from ww w . jav a2 s .c o m return file.getAbsoluteFile(); } }
From source file:jeplus.JEPlusProject.java
/** * Read a project from an XML file. The members of this project are not updated. * @param fn The File object associated with the file * @return a new project instance from the file *///from w w w . j ava 2s.c om public static JEPlusProject loadAsXML(File fn) { JEPlusProject proj; try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(fn)))) { proj = ((JEPlusProject) decoder.readObject()); } catch (Exception ex) { logger.error("Error loading project from file " + fn, ex); return null; } String dir = fn.getAbsoluteFile().getParent(); dir = dir.concat(dir.endsWith(File.separator) ? "" : File.separator); // proj.updateBaseDir(dir); proj.setBaseDir(dir); if (proj.ParamFile != null) { // Load parameters from text file proj.importParameterTableFile(new File(RelativeDirUtil.checkAbsolutePath(proj.ParamFile, dir))); } else { // Reassign reference to project in all parameters if (proj.getParamTree() != null) { Enumeration params = proj.getParamTree().breadthFirstEnumeration(); while (params.hasMoreElements()) { ((ParameterItem) ((DefaultMutableTreeNode) params.nextElement()).getUserObject()) .setProject(proj); } } } // Assign the first branch to the Parameters list DefaultMutableTreeNode thisleaf = proj.getParamTree().getFirstLeaf(); Object[] path = thisleaf.getUserObjectPath(); proj.setParameters(new ArrayList<ParameterItem>()); for (Object item : path) { proj.getParameters().add((ParameterItem) item); } // Load Rvx if a RVX file is available try { proj.Rvx = RVX.getRVX(proj.resolveRVIDir() + proj.getRVIFile()); } catch (IOException ioe) { logger.error("Cannot read the project's RVX file", ioe); } // done return proj; }