List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:cz.lbenda.rcp.DialogHelper.java
/** Ask user if file can be overwrite if file exist * @param file file which is rewrite// www. ja v a 2 s. c om * @param defaultExtension if file haven't extension then default is add * @return file if user want rewrite it, or no file with this name exist */ public File canBeOverwriteDialog(File file, String defaultExtension) { if (file == null) { return null; } if ("".equals(FilenameUtils.getExtension(file.getName()))) { file = new File(file.getAbsoluteFile() + "." + defaultExtension); } if (!file.exists()) { return file; } Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle(msgCanOverwriteTitle); alert.setContentText(String.format(msgCanOverwriteContent, file.getName())); Optional<ButtonType> result = alert.showAndWait(); return (result.isPresent()) && (result.get() == ButtonType.OK) ? file : null; }
From source file:chibi.gemmaanalysis.OutlierDetectionTestCli.java
@Override protected Exception doWork(String[] args) { Exception err = processCommandLine(args); if (err != null) { return err; }//from www . j a va 2s. c o m File file = new File(outputFileName); try { file.createNewFile(); try (FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw);) { if (useCombinedMethod) bw.write(HEADER_COMBINED); else if (findByMedian && useRegression) bw.write(HEADER_BY_MEDIAN_REG); else if (findByMedian) bw.write(HEADER_BY_MEDIAN); else if (useRegression) { bw.write(HEADER_REG); } else { bw.write(HEADER); } bw.newLine(); for (BioAssaySet bas : expressionExperiments) { if (!(bas instanceof ExpressionExperiment)) continue; ExpressionExperiment ee = (ExpressionExperiment) bas; try { OutlierDetectionTestDetails testDetails = findOutliers(ee); if (useCombinedMethod) { writeResultsToFileCombined(bw, ee, testDetails); } else if (findByMedian) { writeResultsToFileByMedian(bw, ee, testDetails); } else { writeResultsToFileBasic(bw, ee, testDetails); } bw.flush(); } catch (Exception e) { log.error("Error while processing " + ee + ": " + e.getMessage()); errorObjects.add(ee + ": " + e.getMessage()); continue; } successObjects.add(ee.toString()); } } } catch (Exception e) { log.error("Caught exception: " + e); } finally { summarizeProcessing(); } return null; }
From source file:Json.JsonCodes.java
public void jsonCreate(String patchName) { JSONObject obj = new JSONObject(); JSONArray ar = new JSONArray(); for (int i = 0; i < this.pageList.size(); i++) { ar.add(this.pageList.get(i)); }/*w w w . j a va 2 s .c o m*/ obj.put("patch", this.patch); obj.put("page", ar); File file = new File(patchName); try { //?, ? ?? ? if (!file.exists()) { file.createNewFile(); } //PrintWriter ? ? ? PrintWriter out = new PrintWriter(file.getAbsoluteFile()); try { //? ? out.print(obj); } finally { //? // ?? out.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePublicKeyDataProvider.java
@Test public void testKeyFile01() throws IOException { final String fileName = "testKeyFile01.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);/* ww w . j av a2 s. c o m*/ FilePublicKeyDataProvider provider = new FilePublicKeyDataProvider(fileName); assertNotNull("The key file should not be null.", provider.getPublicKeyFile()); assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPublicKeyFile()); assertFalse("The paths should not be the same.", fileName.equals(provider.getPublicKeyFile().getPath())); assertTrue("The paths should end the same.", provider.getPublicKeyFile().getPath().endsWith(fileName)); }
From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java
@Test public void testKeyFile01() throws IOException { final String fileName = "testKeyFile01.key"; File file = new File(fileName); if (file.exists()) FileUtils.forceDelete(file);// w w w.ja va 2s. co m FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(fileName); assertNotNull("The key file should not be null.", provider.getPrivateKeyFile()); assertEquals("The key file is not correct.", file.getAbsoluteFile(), provider.getPrivateKeyFile()); assertFalse("The paths should not be the same.", fileName.equals(provider.getPrivateKeyFile().getPath())); assertTrue("The paths should end the same.", provider.getPrivateKeyFile().getPath().endsWith(fileName)); }
From source file:net.sf.jclal.util.xml.XMLConfigurationReader.java
/** * Constructor/*from w w w . j a va 2 s.co m*/ * * @param file The file path of the xml configuration. * @throws Exception The exception that will be launched */ public XMLConfigurationReader(File file) throws Exception { this.file = file.getAbsoluteFile(); initReader(); }
From source file:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java
/** * Checks to see if any files in the database need to be copied to the database. A file may not * exist or be out of date.//from w w w . java 2 s. c o m */ protected static void refreshCacheFromDatabase(final String mimeType) { File cachePath = getCachePath(); Hashtable<String, File> hash = new Hashtable<String, File>(); for (File f : cachePath.listFiles()) { //log.info("Report Cache File["+f.getName()+"]"); hash.put(f.getName(), f); } for (AppResourceIFace ap : AppContextMgr.getInstance().getResourceByMimeType(mimeType)) { // Check to see if the resource or file has changed. boolean updateCache = false; File fileFromJasperCache = hash.get(ap.getName()); if (fileFromJasperCache == null) { updateCache = true; } else { Date fileDate = new Date(fileFromJasperCache.lastModified()); Timestamp apTime = ap.getTimestampModified() == null ? ap.getTimestampCreated() : ap.getTimestampModified(); updateCache = apTime == null || fileDate.getTime() < apTime.getTime(); } // If it has changed then copy the contents into the cache and delete the compiled file // so it forces it to be recompiled. if (updateCache) { File localFilePath = new File(cachePath.getAbsoluteFile() + File.separator + ap.getName()); try { XMLHelper.setContents(localFilePath, ap.getDataAsString()); File compiledFile = getCompiledFile(localFilePath); if (compiledFile.exists()) { compiledFile.delete(); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JasperReportsCache.class, ex); throw new RuntimeException(ex); } } } }
From source file:net.sf.jclal.util.xml.XMLConfigurationBuilder.java
/** * * @param file The file path of the xml configuration. * @param replace If the file exists, replace with the new one. * @throws Exception The exception that will be launched */// w ww.j a va 2s. co m public XMLConfigurationBuilder(File file, boolean replace) throws Exception { this.file = file.getAbsoluteFile(); FileUtil.createFile(file, replace); initBuilder(); }
From source file:com.github.kaklakariada.aws.sam.PluginTest.java
private void runBuild(File projectDir, String... arguments) { final List<String> argsList = new ArrayList<>(); argsList.addAll(asList(arguments));// w w w .j av a 2 s .c om argsList.addAll(asList("-Pstage=" + STAGE, "--info", "--stacktrace", "--max-workers", "1")); argsList.addAll(getCustomProjectParameters()); buildResult = GradleRunner.create().withProjectDir(projectDir.getAbsoluteFile()) // .withPluginClasspath() // .withArguments(argsList) // .forwardOutput() // .build(); }
From source file:architecture.ee.web.logo.DefaultLogoManager.java
protected File getThumbnailFromCacheIfExist(LogoImage image, int width, int height) throws IOException { try {/*w ww. ja v a 2 s . co m*/ lock.lock(); log.debug("thumbnail : " + width + " x " + height); File dir = getImageCacheDir(); File file = new File(dir, toThumbnailFilename(image, width, height)); File originalFile = getImageFromCacheIfExist(image); log.debug("orignal image source: " + originalFile.getAbsoluteFile() + ", " + originalFile.length() + " thumbnail:" + file.getAbsoluteFile() + " - " + file.exists()); if (file.exists()) { log.debug(file.length()); if (file.length() > 0) { image.setThumbnailSize((int) file.length()); return file; } else { } } /** * TIP : ? Thumbnail ? ??? ?? ?. */ log.debug("create thumbnail : " + file.getAbsolutePath()); if (Platform.current() == Platform.WINDOWS) { File tmp = getTemeFile(); Thumbnails.of(originalFile).size(width, height).outputFormat("png") .toOutputStream(new FileOutputStream(tmp)); image.setThumbnailSize((int) tmp.length()); FileUtils.copyFile(tmp, file); } else { try { Thumbnails.of(originalFile).allowOverwrite(true).size(width, height).outputFormat("png") .toOutputStream(new FileOutputStream(file)); } catch (Throwable e) { log.error(e); } image.setThumbnailSize((int) file.length()); } return file; } finally { lock.unlock(); } }