List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:ezbake.frack.submitter.util.JarUtil.java
public static File addFilesToJar(File sourceJar, List<File> newFiles) throws IOException { JarOutputStream target = null; JarInputStream source;/*w ww . ja v a 2 s . co m*/ File outputJar = new File(sourceJar.getParentFile(), getRepackagedJarName(sourceJar.getAbsolutePath())); log.debug("Output file created at {}", outputJar.getAbsolutePath()); outputJar.createNewFile(); try { source = new JarInputStream(new FileInputStream(sourceJar)); target = new JarOutputStream(new FileOutputStream(outputJar)); ZipEntry entry = source.getNextEntry(); while (entry != null) { String name = entry.getName(); // Add ZIP entry to output stream. target.putNextEntry(new ZipEntry(name)); // Transfer bytes from the ZIP file to the output file int len; byte[] buffer = new byte[BUFFER_SIZE]; while ((len = source.read(buffer)) > 0) { target.write(buffer, 0, len); } entry = source.getNextEntry(); } source.close(); for (File fileToAdd : newFiles) { add(fileToAdd, fileToAdd.getParentFile().getAbsolutePath(), target); } } finally { if (target != null) { log.debug("Closing output stream"); target.close(); } } return outputJar; }
From source file:Main.java
public static void createFile(File file, boolean isFile) { if (!file.exists()) { if (!file.getParentFile().exists()) { createFile(file.getParentFile(), false); } else {/* w ww . ja v a 2 s. c o m*/ if (isFile) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else { file.mkdir(); } } } }
From source file:edu.asu.cse564.samples.crud.io.GradebookIO.java
public static void writeToGradebook(List<Gradebook> gradebookList, String filename) { //GradebookIO gbio = new GradebookIO(); try {//from ww w . ja v a 2 s.c om //String path = gbio.getPath(filename); String path = filename; File file = new File(path); // if file doesnt exists, then create it if (!file.exists()) { LOG.info("Creating file as it does not exist"); file.createNewFile(); LOG.debug("Created file = {}", file.getAbsolutePath()); } String jsonString = null; jsonString = Converter.convertFromObjectToJSON(gradebookList, gradebookList.getClass()); LOG.info("File path = {}", file.getAbsolutePath()); FileWriter fw = new FileWriter(file.getAbsoluteFile()); try (BufferedWriter bw = new BufferedWriter(fw)) { bw.write(jsonString); } } catch (Exception e) { e.printStackTrace(); ; } }
From source file:com.bluexml.side.util.documentation.LogSave.java
/** * Render a SIDELog to a xml file using the given fileName in the given * folderName/*from w ww.ja va 2 s .co m*/ * * @param log * @param fileName * @param folderName * @throws Exception */ public static void toXml(SIDELog log, String fileName, String folderName) throws Exception { IFolder folder = IFileHelper.createFolder(folderName); File f = IFileHelper.getFile(folder); FileWriterWithEncoding fos; File file = new File(f, fileName); file.createNewFile(); fos = new FileWriterWithEncoding(file, "UTF-8"); toXml(log, fos); IFileHelper.refreshFolder(folder); fos.close(); }
From source file:com.bluexml.side.m2.repositoryBuilder.Builder.java
private static void writeShellScript(File script, List<File> poms) throws Exception { // create file if (!script.exists()) { script.createNewFile(); }/*from ww w . j ava 2 s . co m*/ FileWriter fw = new FileWriter(script); // write header String header = "#!/bin/bash\n"; header += "if [ $# -eq 1 ]; then" + "\n"; header += " MAVENREPO=$1" + "\n"; header += "else" + "\n"; header += " echo \"Usage: patcher.sh MAVENREPO\"" + "\n"; header += " echo \" with MAVENREPO = maven.repo.local absolute path\"" + "\n"; header += " exit -2" + "\n"; header += "fi" + "\n"; fw.write(header); for (File file : poms) { fw.write("mvn dependency:go-offline -P public -f " + file.getAbsolutePath() + " -Dmaven.repo.local=$MAVENREPO\n"); } // save close fw.flush(); fw.close(); }
From source file:de.dakror.villagedefense.util.SaveHandler.java
public static void addWorldScorePosted(int worldCreated) { File f = new File(CFG.DIR, "scores"); try {//from w ww .j a v a 2 s . co m f.createNewFile(); Helper.setFileContent(f, Helper.getFileContent(f) + worldCreated + "\r\n"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.bluexml.side.util.documentation.LogSave.java
public static void toXml(SIDELog log, String fileName, File folder) throws Exception { folder.mkdirs();// www . j a va2s. c o m FileWriterWithEncoding fos; File file = new File(folder, fileName); file.createNewFile(); fos = new FileWriterWithEncoding(file, "UTF-8"); toXml(log, fos); fos.close(); }
From source file:com.project.utilities.Utilities.java
public static void writeToFileViolationListJSON() { String violationJSONList = getRequest(Constants.API_VIOLATIONS); File currentConfig = new File(Constants.EXTERNAL_DIRECTORY + "/" + Constants.FILENAME_VIOLATION_JSON); try {//from ww w .j av a2s . co m currentConfig.createNewFile(); FileOutputStream fos = new FileOutputStream(currentConfig); fos.write(violationJSONList.getBytes()); fos.close(); } catch (IOException e) { Log.e("ERROR CREATING JSON FILE", e.getMessage().toString()); } }
From source file:index.IncrementIndex.java
public static String getStoreId(String path) { String storeId = ""; try {/*from w ww. ja v a 2s . com*/ File file = new File(path); if (!file.exists()) { file.createNewFile(); } FileReader fr = new FileReader(path); BufferedReader br = new BufferedReader(fr); storeId = br.readLine(); if (storeId == null || storeId == "") storeId = "0"; br.close(); fr.close(); } catch (Exception e) { e.printStackTrace(); } return storeId; }
From source file:index.IncrementIndex.java
/** * id//from w ww.j a v a 2s .c o m * @param path * @param storeId * @return */ public static boolean writeStoreId(String path, String storeId) { boolean b = false; try { File file = new File(path); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(path); PrintWriter out = new PrintWriter(fw); out.write(storeId); out.close(); fw.close(); b = true; } catch (IOException e) { e.printStackTrace(); } return b; }