List of usage examples for java.io File toString
public String toString()
From source file:com.cloudera.sqoop.util.DirectImportUtils.java
/** * Executes chmod on the specified file, passing in the mode string 'modstr' * which may be e.g. "a+x" or "0600", etc. * @throws IOException if chmod failed.//from w w w . ja v a 2 s.c o m */ public static void setFilePermissions(File file, String modstr) throws IOException { // Set this file to be 0600. Java doesn't have a built-in mechanism for this // so we need to go out to the shell to execute chmod. try { Shell.execCommand("chmod", modstr, file.toString()); } catch (IOException ioe) { // Shell.execCommand will throw IOException on exit code != 0. LOG.error("Could not chmod " + modstr + " " + file.toString()); throw new IOException("Could not ensure password file security.", ioe); } }
From source file:Main.java
public static String unzip(String filename) throws IOException { BufferedOutputStream origin = null; String path = null;/* w w w . j a v a 2s. co m*/ Integer BUFFER_SIZE = 20480; if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File flockedFilesFolder = new File( Environment.getExternalStorageDirectory() + File.separator + "FlockLoad"); System.out.println("FlockedFileDir: " + flockedFilesFolder); String compressedFile = flockedFilesFolder.toString() + "/" + filename; System.out.println("compressed File name:" + compressedFile); //String uncompressedFile = flockedFilesFolder.toString()+"/"+"flockUnZip"; File purgeFile = new File(compressedFile); try { ZipInputStream zin = new ZipInputStream(new FileInputStream(compressedFile)); BufferedInputStream bis = new BufferedInputStream(zin); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { byte data[] = new byte[BUFFER_SIZE]; path = flockedFilesFolder.toString() + "/" + ze.getName(); System.out.println("path is:" + path); if (ze.isDirectory()) { File unzipFile = new File(path); if (!unzipFile.isDirectory()) { unzipFile.mkdirs(); } } else { FileOutputStream fout = new FileOutputStream(path, false); origin = new BufferedOutputStream(fout, BUFFER_SIZE); try { /* for (int c = bis.read(data, 0, BUFFER_SIZE); c != -1; c = bis.read(data)) { origin.write(c); } */ int count; while ((count = bis.read(data, 0, BUFFER_SIZE)) != -1) { origin.write(data, 0, count); } zin.closeEntry(); } finally { origin.close(); fout.close(); } } } } finally { bis.close(); zin.close(); purgeFile.delete(); } } catch (Exception e) { e.printStackTrace(); } return path; } return null; }
From source file:io.stallion.services.PermaCache.java
public static void set(String key, String contents) { cache.put(key, contents);/* ww w . ja va 2 s.co m*/ if (!empty(getCacheFolder())) { File file = new File(getCacheFolder() + "/" + DigestUtils.md5Hex(key)); try { FileUtils.write(file, contents, "utf-8"); } catch (IOException e) { Log.exception(e, "Error writing file to cache: " + file.toString()); } } }
From source file:core.Utility.java
private static ArrayList<String> getSynonymsWordnet(String _word) { ArrayList<String> _list = new ArrayList(); File f = new File("WordNet\\2.1\\dict"); System.setProperty("wordnet.database.dir", f.toString()); WordNetDatabase database = WordNetDatabase.getFileInstance(); Synset[] synsets = database.getSynsets(_word); if (synsets.length > 0) { HashSet hs = new HashSet(); for (Synset synset : synsets) { String[] wordForms = synset.getWordForms(); _list.addAll(Arrays.asList(wordForms)); }// w w w .j av a 2 s . co m hs.addAll(_list); _list.clear(); _list.addAll(hs); } return _list; }
From source file:Main.java
public static void DownloadFile(String u) { try {//from www . j av a2s .co m Logd(TAG, "Starting download of: " + u); URL url = new URL(u); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); //File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); checkStorageDir(); File storageDir = new File( Environment.getExternalStorageDirectory() + "/Android/data/com.nowsci.odm/.storage"); File file = new File(storageDir, getFileName(u)); Logd(TAG, "Storage directory: " + storageDir.toString()); Logd(TAG, "File name: " + file.toString()); FileOutputStream fileOutput = new FileOutputStream(file); InputStream inputStream = urlConnection.getInputStream(); byte[] buffer = new byte[1024]; int bufferLength = 0; while ((bufferLength = inputStream.read(buffer)) > 0) { fileOutput.write(buffer, 0, bufferLength); } fileOutput.close(); Logd(TAG, "File written"); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.phonegap.DirectoryManager.java
/** * Determine if a file or directory exists. * /* w w w. j a va 2 s.c o m*/ * @param name The name of the file to check. * @return T=exists, F=not found */ protected static boolean testFileExists(String name) { boolean status; // If SD card exists if ((testSaveLocationExists()) && (!name.equals(""))) { File path = Environment.getExternalStorageDirectory(); File newPath = constructFilePaths(path.toString(), name); status = newPath.exists(); } // If no SD card else { status = false; } return status; }
From source file:com.phonegap.DirectoryManager.java
/** * Create directory on SD card./*from w ww . ja v a2s . c o m*/ * * @param directoryName The name of the directory to create. * @return T=successful, F=failed */ protected static boolean createDirectory(String directoryName) { boolean status; // Make sure SD card exists if ((testSaveLocationExists()) && (!directoryName.equals(""))) { File path = Environment.getExternalStorageDirectory(); File newPath = constructFilePaths(path.toString(), directoryName); status = newPath.mkdir(); status = true; } // If no SD card or invalid dir name else { status = false; } return status; }
From source file:com.plotsquared.iserver.util.FileUtils.java
public static String getDocument(final File file, int buffer, boolean create) { final Optional<String> cacheEntry = Server.getInstance().getCacheManager().getCachedFile(file.toString()); if (cacheEntry.isPresent()) { return cacheEntry.get(); }//from w w w.j ava 2s. c o m StringBuilder document = new StringBuilder(); try { if (!file.exists()) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (create) { file.createNewFile(); return ""; } } BufferedReader reader = new BufferedReader(new FileReader(file), buffer); String line; while ((line = reader.readLine()) != null) { document.append(line).append("\n"); } reader.close(); } catch (final Exception e) { e.printStackTrace(); } final String content = document.toString(); Server.getInstance().getCacheManager().setCachedFile(file.toString(), content); return content; }
From source file:Main.java
static public void CopyAsset(Context ctx, File path, String filename) throws IOException { AssetManager assetManager = ctx.getAssets(); InputStream in = null;/* ww w . j a v a2s. c o m*/ OutputStream out = null; // Copy files from asset folder to application folder try { in = assetManager.open(filename); out = new FileOutputStream(path.toString() + "/" + filename); copyFile(in, out); } catch (IOException e) { Log.e(TAG, e.getMessage()); throw e; } finally { // Reclaim resources if (in != null) { in.close(); in = null; } if (out != null) { out.flush(); out.close(); out = null; } } }
From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java
public static Par getParDefinition(IProject project) { // Create a resource set to hold the resources. ResourceSet resourceSet = new ResourceSetImpl(); // Register the package to ensure it is available during loading. resourceSet.getPackageRegistry().put(ParPackage.eNS_URI, ParPackage.eINSTANCE); File parFile = new File(new File(project.getLocation().toString() + File.separatorChar + ".settings"), "org.eclipse.virgo.ide.runtime.core.par.xml"); if (parFile.exists()) { URI fileUri = URI.createFileURI(parFile.toString()); Resource resource = resourceSet.getResource(fileUri, true); return (Par) resource.getContents().iterator().next(); }//from www . j av a 2 s.co m return null; }