List of usage examples for java.io File getPath
public String getPath()
From source file:Compress.java
/** Zip the contents of the directory, and save it in the zipfile */ public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException { // Check that the directory is a directory, and get its contents File d = new File(dir); if (!d.isDirectory()) throw new IllegalArgumentException("Not a directory: " + dir); String[] entries = d.list();//ww w . j a v a 2 s. c o m byte[] buffer = new byte[4096]; // Create a buffer for copying int bytesRead; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile)); for (int i = 0; i < entries.length; i++) { File f = new File(d, entries[i]); if (f.isDirectory()) continue;//Ignore directory FileInputStream in = new FileInputStream(f); // Stream to read file ZipEntry entry = new ZipEntry(f.getPath()); // Make a ZipEntry out.putNextEntry(entry); // Store entry while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead); in.close(); } out.close(); }
From source file:ImageUtil.java
/** * get image thumbnail/*from www . j a va 2s . co m*/ * @param imageFile */ public static ImageIcon getImageThumbnail(File imageFile, int width, int height) { ImageIcon thumbnail = null; if (imageFile != null && imageFile.isFile()) { ImageIcon tmpIcon = new ImageIcon(imageFile.getPath()); if (tmpIcon != null) { if (tmpIcon.getIconWidth() > width) { int targetHeight = width / tmpIcon.getIconWidth() * tmpIcon.getIconHeight(); if (targetHeight > height) { targetHeight = height; } else { targetHeight = -1; } thumbnail = new ImageIcon( tmpIcon.getImage().getScaledInstance(width, targetHeight, Image.SCALE_AREA_AVERAGING)); } else { thumbnail = tmpIcon; } } } return thumbnail; }
From source file:com.shmsoft.dmass.services.Util.java
/** * Delete directory with everything underneath. Note that in the case of *nix we use 'rm -fr <dir>, because of * the known problems with recursive deletes, and because 'rm -fr' is probably faster. * @param dir directory to delete.// w w w.j a v a 2s . c o m * @throws IOException on any problem with delete. */ public static void deleteDirectory(File dir) throws IOException { if (PlatformUtil.isNix()) { PlatformUtil.runUnixCommand("rm -fr " + dir.getPath()); } else { FileUtils.deleteDirectory(dir); } }
From source file:net.ontopia.utils.PropertyUtils.java
/** * INTERNAL; Reads properties from a file. *//*from w w w.j a va 2 s . c o m*/ public static Properties loadProperties(File propfile) throws IOException { if (!propfile.exists()) throw new OntopiaRuntimeException("Property file '" + propfile.getPath() + "' does not exist."); // Load properties from file Properties properties = new Properties(); properties.load(new FileInputStream(propfile)); return properties; }
From source file:Main.java
public static File getEmptyFileWithStructuredPath(String course_title, String format) { Calendar calendar = Calendar.getInstance(); int date = calendar.get(Calendar.DATE); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); StringBuffer dateInString = new StringBuffer(); dateInString.append(month);// w ww . j a v a 2s.c om dateInString.append("-"); dateInString.append(date); dateInString.append("-"); dateInString.append(year); StringBuffer timeInString = new StringBuffer(); timeInString.append(hour); timeInString.append("_"); timeInString.append(minute); timeInString.append("_"); timeInString.append(second); Log.d("File Storage", "DateTime : " + dateInString + timeInString); String folderPathInString = Environment.getExternalStorageDirectory().toString() + "/" + LECTURE_HELPER + "/" + course_title + "/" + dateInString + "/"; File folderPath = new File(folderPathInString); if (!folderPath.exists()) { folderPath.mkdirs(); } return new File(folderPath.getPath() + "/" + FILE_NAME_TO_SAVE + timeInString + format); }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * get file entry name according to base * @param base/*from w ww. java 2 s.c om*/ * base to split the total file * @param file * file to get the entry * @return entry name. */ private static String getEntryName(String base, File file) { File baseFile = new File(base); String filename = file.getPath(); if (baseFile.getParentFile().getParentFile() == null) { return filename.substring(baseFile.getParent().length()); } // d:/file1 /file2/text.txt /*d:/file1/text.txt*/ return filename.substring(baseFile.getParent().length() + 1); }
From source file:Main.java
/** * Decodes an image File to Bitmap resizing the image to be <code>inSampleSize</code> times smaller then the original. * @param file the image file reference/*from w w w. j a va2 s .c o m*/ * @param inSampleSize how much smaller that the image will be, for example, <code>inSampleSize</code> equals 2 will return an image 1/2 the size of the original * @return the resized Bitmap */ public static Bitmap decodeSampledBitmapFromFile(File file, int inSampleSize) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = inSampleSize; return BitmapFactory.decodeFile(file.getPath(), options); }
From source file:Main.java
/** * Write the String into the given File//from ww w. j a v a2 s . c o m * @param baseString * @param mainStyleFile */ public static void writeStyleFile(String baseString, File mainStyleFile) { FileWriter fw = null; try { fw = new FileWriter(mainStyleFile); fw.write(baseString); Log.i("STYLE", "Style File updated:" + mainStyleFile.getPath()); } catch (FileNotFoundException e) { Log.e("STYLE", "unable to write open file:" + mainStyleFile.getPath()); } catch (IOException e) { Log.e("STYLE", "error writing the file: " + mainStyleFile.getPath()); } finally { try { if (fw != null) { fw.close(); } } catch (IOException e) { // ignored } } }
From source file:net.librec.util.Systems.java
/** * Capture screen with the input string as file name * * @param fileName a given file name//from ww w . j a v a 2s.c o m * @throws Exception if error occurs */ public static void captureScreen(String fileName) throws Exception { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); File file = new File(fileName); ImageIO.write(image, "png", file); LOG.debug("A screenshot is captured to: " + file.getPath()); }
From source file:gov.nih.nci.cabig.caaers.testdata.TestDataFileUtils.java
public static File createFolder(File f) { if (!f.exists()) f.mkdir();//from ww w . j a v a2 s. c om if (!f.isDirectory()) throw new RuntimeException("The folder " + f.getPath() + ", unable to create"); return f; }