List of usage examples for java.io File toString
public String toString()
From source file:jeplus.INSELWinTools.java
/** * Create working directory and prepare input files for simulation * @param workdir The directory to be created * @return Preparation successful or not */// ww w . ja va2 s . c om public static boolean prepareWorkDir(String workdir) { boolean success = true; // Create the directory File dir = new File(workdir); if (!dir.exists()) { success = dir.mkdirs(); } else if (!dir.isDirectory()) { System.err.println(dir.toString() + " is present but not a directory."); success = false; } if (success) { // Copying all include and external files to the work directory // success = success && fileCopy(weatherfile, workdir + EPlusConfig.getEPDefEPW()); // if (! success) // System.err.println("TRNSYSWinTools.prepareWorkDir(): cannot copy all neccessray files to the working directory."); File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) files[i].delete(); } return success; }
From source file:dao.EntryDaoTest.java
@BeforeClass public static void setUpClass() { String fSeparator = File.separator; try {/*from w w w .j a va2 s . c o m*/ File folder = new File( System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "Texnologia2"); folder.mkdirs(); File textFolder = new File(folder.toString() + fSeparator + "Texts"); textFolder.mkdirs(); File textFile = new File(textFolder.toString() + fSeparator + "test.txt"); BufferedWriter bw; FileWriter fw; fw = new FileWriter(textFile, true); bw = new BufferedWriter(fw); bw.write("test0123456789"); if (bw != null) bw.close(); fw.close(); File imageFolder = new File(folder.toString() + fSeparator + "Images"); imageFolder.mkdirs(); String imageSourcePath = System.getProperty("user.dir") + fSeparator + "src" + fSeparator + "test" + fSeparator + "java" + fSeparator + "resources" + fSeparator + "testImg.jpg"; File imageSourceFile = new File(imageSourcePath); FileUtils.copyFileToDirectory(imageSourceFile, imageFolder); String videoSourcePath = System.getProperty("user.dir") + fSeparator + "src" + fSeparator + "test" + fSeparator + "java" + fSeparator + "resources" + fSeparator + "testVideo.mp4"; File videoSourceFile = new File(videoSourcePath); File videoFolder = new File(folder.toString() + fSeparator + "Videos"); videoFolder.mkdirs(); FileUtils.copyFileToDirectory(videoSourceFile, videoFolder); } catch (IOException ex) { Logger.getLogger(EntryDaoTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.stallion.services.PermaCache.java
public static String get(String key) { if (cache.containsKey(key)) { return cache.get(key); }//from w w w . j a v a 2s. c o m if (!empty(getCacheFolder())) { File file = new File(getCacheFolder() + "/" + DigestUtils.md5Hex(key)); if (file.exists()) { try { String content = FileUtils.readFileToString(file, "utf-8"); cache.put(key, content); return content; } catch (IOException e) { Log.exception(e, "Error reading file from disk: " + file.toString()); } } } return null; }
From source file:Main.java
/** * Writes file to external storage and returns the filename. * Writes as a JPEG file.//from w w w . j av a 2 s. com * If you want to convert to a URI you need to prepend file:// * @param b * @param fileName * @return */ static public String saveImageToExternal(Bitmap b, String fileName) { //}, int width, int height) { FileOutputStream fos; String mypath = Environment.getExternalStorageDirectory() + "/" + fileName + ".jpg"; File file = new File(mypath); try { file.createNewFile(); fos = new FileOutputStream(file); // Use the compress method on the BitMap object to write image to the OutputStream b.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } ; return file.toString(); }
From source file:com.itmanwuiso.checksums.FileDuplicateChecker.java
private static void createTaske(File file) { try {/* w w w .ja v a 2 s. co m*/ if (file.isFile()) { HashTask task = new HashTask(file, hashers, storage); FileDuplicateChecker.increment(); checksumPool.execute(task); } } catch (Exception e) { logger.error(file.toString(), e); } }
From source file:it.cnr.isti.thematrix.mapping.utils.TempFileManager.java
/** * get a File pointing to a fresh new temporary file in the iad directory * @return the new temporary file/*from w ww . j a va 2 s . c o m*/ */ public static File newTempFile() { File tempFile; File dir = new File(Dynamic.getResultsPath()); String suffix = Enums.getFileExtension(Dynamic.bufferCompression); try { tempFile = java.io.File.createTempFile("test", suffix, dir); } catch (IOException e) { throw new Error( "TempFileManager - Can't open temp file " + dir.toString() + " exception " + e.toString()); } filenameList.add(tempFile.getAbsolutePath()); return tempFile; }
From source file:net.ftb.util.FTBFileUtils.java
public static void move(File oldFile, File newFile) { try {// w ww . j a va2s . c o m if (oldFile.exists() && !newFile.exists()) { FileUtils.moveFile(oldFile, newFile); } } catch (IOException e) { Logger.logWarn("Exception occurred while moving " + oldFile.toString() + " : " + e.getMessage()); } }
From source file:mcp.tools.nmap.parser.NmapXmlParser.java
public static void parse(File xmlResultsFile, String scanDescription, String commandLine) { Pattern endTimePattern = Pattern.compile("<runstats><finished time=\"(\\d+)"); String xmlResults;/* w ww .j a v a 2 s.c om*/ try { xmlResults = FileUtils.readFileToString(xmlResultsFile); } catch (IOException e) { logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': " + e.getLocalizedMessage(), e); return; } Matcher m = endTimePattern.matcher(xmlResults); Instant scanTime = null; if (m.find()) { int t; try { t = Integer.parseInt(m.group(1)); scanTime = Instant.ofEpochSecond(t); } catch (NumberFormatException e) { } } if (scanTime == null) { logger.debug("Failed to find scan completion time in nmap results. Using current time."); scanTime = Instant.now(); } String path; try { path = xmlResultsFile.getCanonicalPath(); } catch (IOException e1) { logger.debug("Why did the canonical path fail?"); path = xmlResultsFile.getAbsolutePath(); } NmapScanSource source = new NmapScanSourceImpl(path, scanDescription, commandLine); NMapXmlHandler nmxh = new NMapXmlHandler(scanTime, source); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp; try { sp = spf.newSAXParser(); } catch (ParserConfigurationException e) { throw new UnexpectedException("This shouldn't have happened: " + e.getLocalizedMessage(), e); } catch (SAXException e) { throw new UnexpectedException("This shouldn't have happened: " + e.getLocalizedMessage(), e); } try { sp.parse(xmlResultsFile, nmxh); } catch (SAXException e) { logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': " + e.getLocalizedMessage(), e); return; } catch (IOException e) { logger.error("Failed to parse nmap results file '" + xmlResultsFile.toString() + "': " + e.getLocalizedMessage(), e); return; } }
From source file:com.amazonaws.client.regions.RegionUtils.java
/** * Initializes the region metadata singleton from an XML file on disk. * * @param file the file to load from/*from w w w .j a va 2 s.c om*/ * @throws AmazonClientException on error opening or reading from the file */ public static synchronized void initializeFromFile(final File file) { doInitializeFromFile(file); source = file.toString(); }
From source file:edu.cornell.med.icb.goby.alignments.Merge.java
public static void prepareMergedTooManyHits(final String outputFilename, final int numberOfReads, final int minQueryIndex, final File[] inputFiles) throws IOException { final String[] inputFilenames = new String[inputFiles.length]; int i = 0;/*from w w w .ja va 2s .co m*/ for (final File file : inputFiles) { inputFilenames[i++] = file.toString(); } prepareMergedTooManyHits(outputFilename, numberOfReads, minQueryIndex, inputFilenames); }