List of usage examples for java.io File createNewFile
public boolean createNewFile() throws IOException
From source file:com.digitalreasoning.herman.JarCreater.java
public static void createJar(File outputJarFile, List<Entry> entries) throws IOException { if (!outputJarFile.getParentFile().exists()) { outputJarFile.getParentFile().mkdirs(); }/* w w w. jav a2s . co m*/ if (!outputJarFile.exists()) { outputJarFile.createNewFile(); } FileOutputStream fOut = new FileOutputStream(outputJarFile); JarOutputStream jarOut = new JarOutputStream(fOut); Set<String> packageSet = new HashSet<String>(); try { for (Entry folderFile : entries) { InputStream inputStream = folderFile.resource.openStream(); try { if (!packageSet.contains(folderFile.parentFolderName)) { jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName)); jarOut.closeEntry(); packageSet.add(folderFile.parentFolderName); } jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName + (folderFile.parentFolderName.endsWith("/") ? "" : "/") + folderFile.fileName)); IOUtils.copy(inputStream, jarOut); jarOut.closeEntry(); } finally { inputStream.close(); } } } finally { jarOut.close(); fOut.close(); } }
From source file:com.qasp.diego.arsp.Atualiza.java
public static boolean DownloadFTP() throws IOException { final String FTPURL = "37.187.45.24"; final String USUARIO = "diego"; final String SENHA = "Jogador5"; final String ARQUIVO = "data.dat"; FTPClient ftp = new FTPClient(); try {//from w w w. j a v a 2 s .co m ftp.connect(FTPURL); ftp.login(USUARIO, SENHA); ftp.changeWorkingDirectory("/httpdocs/tcc/TCCpython"); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); OutputStream outputStream = null; boolean downloadcomsucesso = false; try { File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ARQUIVO); f.createNewFile(); outputStream = new BufferedOutputStream(new FileOutputStream(f)); downloadcomsucesso = ftp.retrieveFile(ARQUIVO, outputStream); } finally { if (outputStream != null) outputStream.close(); } return downloadcomsucesso; } finally { if (ftp != null) { ftp.logout(); ftp.disconnect(); } } }
From source file:com.dragovorn.dragonbot.api.bot.file.FileManager.java
public static File addFile(File file) { if (!file.exists()) { if (file.isDirectory()) { file.mkdirs();// w ww. j a va2 s . c om } else { try { file.createNewFile(); } catch (IOException exception) { exception.printStackTrace(); } } } pluginAddedFiles.add(file); return file; }
From source file:com.galenframework.javascript.GalenJsApi.java
public static void writeFile(String filePath, String text) throws IOException { File file = new File(filePath); if (!file.exists()) { if (!file.createNewFile()) { throw new IOException("Couldn't create file: " + filePath); }/*from www . ja v a2 s . co m*/ } FileUtils.writeStringToFile(file, text); }
From source file:de.fmaul.android.cmis.utils.StorageUtils.java
private static void ensureOrCreatePathAndFile(File contentFile) { try {/* www . j av a 2s . c o m*/ contentFile.getParentFile().mkdirs(); contentFile.createNewFile(); } catch (IOException iox) { throw new RuntimeException(iox); } }
From source file:ca.marcmeszaros.papyrus.tools.TNManager.java
/** * Downloads and saves the thumbnail of a book to the SD card. * * @param thumbnailURL the URL to the thumbnail * @param isbn the ISBN number of the book * @return {@code true} on success or {@code false} on failure */// w ww .ja v a 2 s . c o m public static boolean saveThumbnail(Bitmap bitmap, String isbn) { // make sure we have access to the SD card if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { try { // if the folder on the SD carld doesn't exist, create it if (!(new File(Environment.getExternalStorageDirectory(), path).exists())) { new File(Environment.getExternalStorageDirectory(), path).mkdirs(); // creates the ".nomedia" file to hide content from "Gallery" new File(Environment.getExternalStorageDirectory(), path + ".nomedia").createNewFile(); } // create the thumbnail File thumbnail = new File(Environment.getExternalStorageDirectory(), path + isbn + ".jpg"); // if the file doesn't exist, create it and get the data if (!thumbnail.exists()) { thumbnail.createNewFile(); FileOutputStream out = new FileOutputStream(thumbnail); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); } } catch (IOException e) { Log.e(TAG, "IOException", e); } } else { return false; } return true; }
From source file:ca.uviccscu.lp.utils.Utils.java
@Deprecated public static boolean checkDir(File f) { l.trace("Checking dir: " + f.getAbsolutePath()); try {//from w w w . j a v a2 s . com boolean a = f.isDirectory(); if (a) { if (f.listFiles().length != 0) { l.error("Directory not empty"); //JDialog jd = new JDialog((JFrame) null, true); int resp = JOptionPane.showConfirmDialog(null, "Directory nonempty: " + f.getAbsolutePath() + ". Proceed? (will wipe)", "Confirm deletion", JOptionPane.YES_NO_OPTION); if (resp == JOptionPane.YES_OPTION) { FileUtils.deleteDirectory(f); } else { l.fatal("Delete denied"); System.exit(1); } } } FileUtils.forceMkdir(f); File test = new File(f.getAbsolutePath() + File.separator + "test.file"); boolean c = test.createNewFile(); return c; } catch (Exception e) { l.fatal("Az directory creation error", e); return false; } }
From source file:Main.java
private static boolean handleFile(int mode, byte[] key, byte[] iv, String sourceFilePath, String destFilePath) { File sourceFile = new File(sourceFilePath); File destFile = new File(destFilePath); try {/*from w ww . jav a2 s . c om*/ if (sourceFile.exists() && sourceFile.isFile()) { if (!destFile.getParentFile().exists()) destFile.getParentFile().mkdirs(); destFile.createNewFile(); InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(destFile); Cipher cipher = initCipher(mode, key, iv, AES_CFB_NOPADDING); CipherInputStream cin = new CipherInputStream(in, cipher); byte[] b = new byte[1024]; int read = 0; while ((read = cin.read(b)) != -1) { out.write(b, 0, read); out.flush(); } cin.close(); in.close(); out.close(); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.fjn.helper.common.io.file.common.FileUtil.java
public static File ensureFileExists(File file) { try {//ww w . j a va 2 s. c o m if (!file.exists()) { if (!file.createNewFile()) { throw new FileDirFaultException(file); } } } catch (Exception e) { e.printStackTrace(); } return file; }
From source file:com.bc.fiduceo.TestUtil.java
public static File copyFileDir(File sourceFile, File targetDirectory) throws IOException { assertTrue(sourceFile.isFile());//from w ww . j a v a 2 s . c o m final String name = sourceFile.getName(); final File targetFile = new File(targetDirectory, name); targetFile.createNewFile(); Files.copy(sourceFile.toPath(), targetFile.toPath(), REPLACE_EXISTING); assertTrue(targetFile.isFile()); return targetFile; }