List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
private static InputStream bitmap2InputStream(Context context, Bitmap bitmap) throws IOException { File file = new File(context.getFilesDir(), "wallpaper.jpg"); if (file.exists()) { file.delete();/* w ww.j a v a2 s . c om*/ } file.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream); fileOutputStream.close(); return filePath2InputStream(file.getAbsolutePath()); }
From source file:Main.java
public static boolean write2SDFromString(String path, String fileName, String input) { boolean flag = true; File file = null; OutputStream output = null;//from w w w . j a va 2 s .c o m try { file = new File(path + fileName); file.createNewFile(); // creatSDDir(path); //file = creatSDFile(path + fileName); output = new FileOutputStream(file); byte buffer[] = input.getBytes(); output.write(buffer, 0, buffer.length); output.flush(); } catch (Exception e) { return false; } finally { try { output.close(); } catch (Exception e) { return flag; } } return flag; }
From source file:functionaltests.dataspaces.TestSubmitJobWithPartiallyUnaccessibleDataSpaces.java
@BeforeClass public static void before() throws Throwable { spaceRoot = tmpFolder.newFolder("space"); spaceRootUser = new File(spaceRoot, "demo"); spaceRootUser.mkdirs();/* www .j a va 2s . c o m*/ deployer = new FileSystemServerDeployer(spaceRoot.getAbsolutePath(), false); SchedulerTHelper.log("Dataspace started in : " + spaceRoot.getAbsolutePath()); File inputFile = new File(spaceRootUser, "myfilein1"); inputFile.createNewFile(); File propertiesfile = new File(configFile.toURI()); String propContent = FileUtils.readFileToString(propertiesfile, Charset.defaultCharset().toString()); String newContent = propContent.replace("$$TOREPLACE$$", deployer.getVFSRootURL()); FileUtils.writeStringToFile(propertiesfile, newContent); schedulerHelper = new SchedulerTHelper(true, propertiesfile.getAbsolutePath()); }
From source file:Main.java
public static void saveBitmap(String filename, Bitmap bitmap) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); if (file.exists()) { file.delete();//from w w w . java2s. com } file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); }
From source file:gov.nih.nci.firebird.commons.test.TestFileUtils.java
/** * Creates a temporary file which will be deleted upon JVM exit. * * @return temporary file/*from w w w. jav a 2s . com*/ * @throws IOException if there is a problem creating a temporary file */ public static File createTemporaryFile() throws IOException { File file = File.createTempFile("temp_", ".tmp"); file.createNewFile(); FileWriter fileWriter = new FileWriter(file); fileWriter.append(SimpleDateFormat.getDateTimeInstance().format(new Date())); fileWriter.flush(); fileWriter.close(); FileUtils.forceDeleteOnExit(file); return file; }
From source file:net.firejack.aws.license.LicenseHelper.java
public static File create(License license) throws IOException, NoSuchAlgorithmException, JAXBException { signature(license);/*from w ww . jav a2s.com*/ File tmp = new File("/tmp/", license.getName() + ".xml"); tmp.getParentFile().mkdirs(); tmp.createNewFile(); FileOutputStream stream = new FileOutputStream(tmp); JAXBContext jaxbContext = JAXBContext.newInstance(License.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(license, stream); stream.close(); return tmp; }
From source file:Main.java
/** * Write to file in given folder/*from w w w . j ava 2 s.c o m*/ * @param fcontent * @return */ public static boolean writeFile(String fcontent, String path) { /* * Write file contents to file path */ try { File file = new File(path); // If file does not exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(fcontent); bw.close(); return true; } catch (Exception e) { return false; } }
From source file:extractcode.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;//from w w w . j ava 2s . co m File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-allcode.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractCode.extractCode(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }
From source file:extractcomments.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;//from ww w . ja va 2s .c om File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractComments.extractComments(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(" isn't a java file."); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }
From source file:extractsomecomments.TraversalFiles.java
public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) { node++;//from www .jav a2 s . com File[] files = inputFile.listFiles(); if (!inputFile.exists()) { System.out.println("File doesn't exist!"); } else if (inputFile.isDirectory()) { path.add(inputFile.getName()); for (File f : files) { for (int i = 0; i < node - 1; i++) { System.out.print(" "); } System.out.print("|-" + f.getPath()); String ext = FilenameUtils.getExtension(f.getName()); if (ext.equals("java")) { try { System.out.println(" => extracted"); //Get extracted file location and add it to output file name, //in order to avoid files in different folder //have the same name. String fileLocation = ""; for (String tmpPath : path) { fileLocation += "-" + tmpPath; } String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-all.txt"; //create output file File outputFile = new File(outFilePath); if (outputFile.createNewFile()) { System.out.println("Create successful: " + outputFile.getName()); } //extract comments ExtractSomeComments.extractComments(f, outputFile); } catch (IOException ex) { Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println(); } fileList(f, node, path, folderPath); } path.remove(node - 1); } }