List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:juicebox.data.HiCFileTools.java
public static PrintWriter openWriter(File file) { try {//from ww w. java2 s .co m file.createNewFile(); return new PrintWriter(new BufferedWriter(new FileWriter(file)), true); } catch (IOException e) { System.out.println("I/O error opening file temp file for AutoSave."); System.exit(0); } return null; }
From source file:com.huawei.streaming.cql.CQLTestCommons.java
/** * //w w w . ja v a 2 s. c o m * * @param f * @param values * @throws IOException ? */ public static void appendToFile(File f, String values) throws IOException { if (!f.exists()) { if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } LOG.warn("file " + f.getPath() + " does not exist! will create it."); if (!f.createNewFile()) { LOG.error("failed to create file " + f.getPath()); return; } } if (f.isDirectory()) { LOG.error("file " + f.getPath() + " is a directory!"); } FileUtils.write(f, values, CHARSET, true); }
From source file:net.orpiske.ssps.common.repository.RepositorySettings.java
/** * Initializes the configuration object/*w w w. j a v a2 s. c om*/ * * @throws SspsException if the configuration file is not found, if the configuration * file is not parseable or if unable to create directories */ public static void initConfiguration() throws SspsException { String repositoryPath = RepositoryUtils.getUserRepository(); String path = repositoryPath + File.separator + "repositories.conf"; if (config == null) { File file = new File(path); if (!file.exists()) { try { if (!file.getParentFile().mkdirs()) { throw new SspsException("Unable to create parent directories"); } if (!file.createNewFile()) { throw new SspsException("Unable to create repository settings file"); } } catch (IOException e) { e.printStackTrace(); } try { config = new PropertiesConfiguration(path); } catch (ConfigurationException e) { throw new SspsException("Unable to load repository configuration: " + e.getMessage(), e); } try { config.save(); } catch (ConfigurationException e) { throw new SspsException("Unable to save repository configuration: " + e.getMessage(), e); } } else { try { config = new PropertiesConfiguration(path); } catch (ConfigurationException e) { throw new SspsException("Unable to load repository configuration: " + e.getMessage(), e); } } } }
From source file:EnumParse.java
public static void praseEnum(JSONObject protocolObject, String keyName, String folderPath, String packageName) throws IOException, JSONException { Iterator<String> keys = protocolObject.keys(); if (null != keyName && keyName.length() > 0) { File dirFolder = new File(folderPath + "/output"); File file = new File(folderPath + "/output/ENUM_" + keyName + ".java"); if (!dirFolder.exists()) { dirFolder.mkdirs();//from ww w . j a va2 s . c o m } if (file.exists()) { file.delete(); } file.createNewFile(); FileOutputStream out = new FileOutputStream(file, true); StringBuffer sb = new StringBuffer(); sb.append("\n"); sb.append("package " + packageName + ";"); sb.append("\n"); sb.append("import java.util.ArrayList;\n" + "import org.json.JSONArray;\n" + "import org.json.JSONException;\n" + "import org.json.JSONObject;\n"); sb.append("\n"); sb.append("public enum " + "ENUM_" + keyName + "\n{\n"); Class enmuClass = null; while (keys.hasNext()) { String key = keys.next(); Object item = protocolObject.get(key); if (item.getClass() == String.class) { sb.append(" " + key + "(\"" + item + "\")"); } else if (item.getClass() == Integer.class) { sb.append(" " + key + "(" + item + ")"); } enmuClass = item.getClass(); if (keys.hasNext()) { sb.append(","); } else { sb.append(";"); } sb.append("\n"); } sb.append("\n " + "private int value = 0;\n"); if (enmuClass == String.class) { sb.append(" " + "private ENUM_" + keyName + "(String initValue)" + "\n {\n this.value = initValue;\n }\n\n"); sb.append(" " + "public int value()\n {\n return this.value;\n }\n"); } else { sb.append(" " + "private ENUM_" + keyName + "(int initValue)" + "\n {\n this.value = initValue;\n }\n\n"); sb.append(" " + "public int value()\n {\n return this.value;\n }\n"); } sb.append("}\n"); out.write(sb.toString().getBytes("utf-8")); out.close(); } }
From source file:com.nearinfinity.mele.MeleBase.java
private static File getNewLocalPath(List<String> pathList, String directoryCluster, String directoryName, Random random) {//ww w . j a va 2 s . co m Collection<String> attempts = new HashSet<String>(); while (true) { if (attempts.size() == pathList.size()) { throw new RuntimeException("no local writable dirs"); } int index = random.nextInt(pathList.size()); String pathname = pathList.get(index); attempts.add(pathname); File file = new File(pathname); file.mkdirs(); File testFile = new File(file, UUID.randomUUID().toString()); try { if (testFile.createNewFile()) { testFile.delete(); File dirFile = new File(new File(file, directoryCluster), directoryName); dirFile.mkdirs(); return dirFile; } } catch (IOException e) { LOG.error("Can not create file on [" + file.getAbsolutePath() + "]"); } } }
From source file:net.naonedbus.utils.InfoDialogUtils.java
/** * Indique si un message n'a pas dj t affich, et le marque comme * affich./*from ww w. j a va 2s . com*/ * * @param context * @param messageId * L'id du message en question. * @return <code>true</code> si le message n'a pas encore t affich, * <code>false</code> s'il l'a dj t. */ public static boolean isNotAlreadyShown(final Context context, final int messageId) { final File dataFile = new File(context.getFilesDir(), MESSAGE_FOLDER + File.separator + messageId); boolean result = true; createDir(context); if (!dataFile.exists()) { try { dataFile.createNewFile(); } catch (final IOException e) { BugSenseHandler.sendExceptionMessage("Erreur lors de la cration du marqueur", null, e); } } else { result = false; } return result; }
From source file:dsd.controller.ParserControler.java
@SuppressWarnings("resource") private static boolean TransferImageToSite(File inFile, File outFile) { if (!outFile.exists()) { try {//from www .ja v a 2 s . c om outFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } } FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(inFile).getChannel(); outChannel = new FileOutputStream(outFile).getChannel(); int maxCount = (64 * 1024 * 1024) - (32 * 1024); long size = inChannel.size(); long position = 0; while (position < size) { position += inChannel.transferTo(position, maxCount, outChannel); } return true; } catch (Exception e) { e.printStackTrace(); } finally { try { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } catch (IOException ex) { ex.printStackTrace(); } } return false; }
From source file:org.liberty.android.fantastischmemo.downloader.DownloaderUtils.java
public static File downloadFile(String url, String savedPath) throws IOException { File outFile = new File(savedPath); OutputStream out;// ww w . ja v a 2 s. c om // Delete and backup if the file exists AMUtil.deleteFileWithBackup(savedPath); // Create the dir if necessary File parentDir = outFile.getParentFile(); parentDir.mkdirs(); outFile.createNewFile(); out = new FileOutputStream(outFile); Log.i(TAG, "URL to download is: " + url); URL myURL = new URL(url); URLConnection ucon = myURL.openConnection(); byte[] buf = new byte[8192]; InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, 8192); int len = 0; while ((len = bis.read(buf)) != -1) { out.write(buf, 0, len); } out.close(); is.close(); return outFile; }
From source file:net.naonedbus.utils.InfoDialogUtils.java
/** * Afficher une dialog avec un message, uniquement si elle n'a pas dj t * affiche/* ww w . j a va2s .c o m*/ * * @param context * @param messageId */ public static void showIfNecessary(final Context context, final int messageId) { final File dataFile = new File(context.getFilesDir(), MESSAGE_FOLDER + File.separator + messageId); createDir(context); if (!dataFile.exists()) { show(context, messageId); try { dataFile.createNewFile(); } catch (final IOException e) { BugSenseHandler.sendExceptionMessage("Erreur lors de la cration du marqueur", null, e); } } }
From source file:juicebox.data.HiCFileTools.java
/** * @param fileName//from www . j a va 2 s .c om * @return */ public static PrintWriter openWriter(String fileName) { try { File file = new File(fileName); file.createNewFile(); file.setWritable(true); return new PrintWriter(new BufferedWriter(new FileWriter(file)), true); } catch (IOException e) { System.out.println("I/O error opening file: " + fileName); System.exit(0); } return null; }