List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:Main.java
public static File getMateralDir(Context context) { File dir = null;/*w ww . j a v a 2 s.co m*/ dir = new File(context.getCacheDir() + File.separator + "wanjia" + File.separator + "material"); File nomediaFile = new File(dir.getAbsolutePath() + File.separator + ".nomedia"); if (!dir.exists()) { dir.mkdirs(); } if (!nomediaFile.exists()) { try { nomediaFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return dir; }
From source file:Main.java
private static long getFileSize(File file) throws Exception { long size = 0; if (file.exists()) { FileInputStream fis = null; fis = new FileInputStream(file); size = fis.available();//from w w w. j av a2 s . com } else { file.createNewFile(); } return size; }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath); File dir = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!dir.exists()) { dir.mkdirs();//from w w w. ja v a 2 s. c o m } file.createNewFile(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); } }
From source file:com.github.tddts.jet.util.Util.java
/** * Save given property to given propeorty file. * * @param fileName property file path/*from w w w.ja v a 2 s . c om*/ * @param key property key * @param value property value */ public static void saveProperty(String fileName, String key, String value) { try { File file = new File(fileName); if (!file.exists()) file.createNewFile(); Properties properties = new Properties(); try (InputStream in = FileUtils.openInputStream(file)) { properties.load(in); } properties.setProperty(key, value); try (OutputStream out = FileUtils.openOutputStream(file)) { properties.store(out, ""); } } catch (IOException e) { throw new ApplicationException(e); } }
From source file:com.vmware.bdd.usermgmt.TestSssdConfigurationGenerator.java
public static void setupSssdTemplates() throws IOException { String tmpDirPath = System.getProperty("java.io.tmpdir"); if (StringUtils.isNotBlank(System.getProperty("serengeti.home.dir"))) { System.setProperty("serengeti.home.dir.bak", System.getProperty("serengeti.home.dir")); }/*from w ww . ja va2s . co m*/ System.setProperty("serengeti.home.dir", tmpDirPath); File usermgmrConfDir = new File( System.getProperty("serengeti.home.dir") + File.separator + "conf" + File.separator + "usermgmt"); usermgmrConfDir.mkdirs(); usermgmrConfDir.deleteOnExit(); File tmpFile = new File(usermgmrConfDir, SssdConfigurationGenerator.SSSD_CONF_TEMPLATES + "LDAP"); tmpFile.createNewFile(); tmpFile.deleteOnExit(); FileCopyUtils.copy(readResource(SssdConfigurationGenerator.SSSD_CONF_TEMPLATES + "LDAP"), new FileWriter(tmpFile)); tmpFile = new File(usermgmrConfDir, SssdConfigurationGenerator.SSSD_CONF_TEMPLATES + "AD_AS_LDAP"); tmpFile.createNewFile(); tmpFile.deleteOnExit(); FileCopyUtils.copy(readResource(SssdConfigurationGenerator.SSSD_CONF_TEMPLATES + "AD_AS_LDAP"), new FileWriter(tmpFile)); }
From source file:com.bluexml.side.clazz.alfresco.reverse.reverser.Reverser.java
public static void executeReverse(Collection<File> alfrescoModels, File sideModelRepo, List<IFile> sideModels, boolean verbose) throws Exception { ReverseScheduler rs = new ReverseScheduler(alfrescoModels, verbose); rs.schedule();/* w w w. j a v a2s. c om*/ Map<Integer, List<Model>> tree = rs.getTree(); // reverse according to scheduled order (import dependencies tree) ReverseModel rm = new ReverseModel(verbose); // load and register EObject from existing SIDE models rm.loadSIDEModels(sideModels); // execute reverse for (Map.Entry<Integer, List<Model>> ent : tree.entrySet()) { for (Model model : ent.getValue()) { EObject sideO = rm.reverse(model); String name = model.getName(); String modelName = ReverseHelper.extractLocalNameFromAlfQName(name); String modelPrefix = ReverseHelper.extractPrefixFromAlfQName(name); File file = new File(sideModelRepo, modelPrefix + StringUtils.capitalize(modelName) + ".dt"); file.getParentFile().mkdirs(); file.createNewFile(); System.out.println("save model :" + file); EResourceUtils.saveModel(file, sideO); } } List<Object> notReverted = rm.getNotReverted(); if (notReverted.size() > 0) { List<String> errorRepport = new ArrayList<String>(); for (Object object : notReverted) { Class c = (Class) object; errorRepport.add(c.getName()); } System.err.println("Fail to reverse Overrides for :" + errorRepport); } }
From source file:com.yata.core.FileManager.java
public static BufferedWriter getFileWriter(String fileName) throws IOException { System.out.println("getFileWriter@" + className + " : File to write in :-> " + fileName); File file = new File(fileName); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); }//from w w w .j a v a2 s. c o m FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); return bufferedWriter; }
From source file:com.opensymphony.util.FileUtils.java
public final static File createFile(String path) { File file = new File(path); try {//from w ww . j a va 2 s .co m file.createNewFile(); } catch (IOException e) { log.error(e); } return file; }
From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java
private static void hideMediaFromGallery(final File gravatars) throws IOException { final File nomedia = new File(gravatars, ".nomedia"); if (!nomedia.exists()) { nomedia.createNewFile(); }//from w w w . java2 s. co m }
From source file:asia.gkc.vneedu.utils.FileUtil.java
/** * //from w w w . j a v a 2 s .c o m * * @param source - ? * @param destination - ? * @return ?? * @throws IOException */ public static boolean transferFile(File source, File destination) throws IOException { if (!destination.exists()) { logger.debug(destination.getPath()); destination.createNewFile(); } FileChannel src, dest; src = new FileInputStream(source).getChannel(); dest = new FileOutputStream(destination).getChannel(); long count = 0; long size = src.size(); while ((count += dest.transferFrom(src, count, size - count)) < size) ; return true; }