Java Code Examples for java.io.File#getAbsolutePath()
The following examples show how to use
java.io.File#getAbsolutePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainTest.java From eml-to-pdf-converter with Apache License 2.0 | 6 votes |
@Test public void main_simplePlainMessage() throws MessagingException, IOException, URISyntaxException { File tmpPdf = File.createTempFile("emailtopdf", ".pdf"); String eml = new File(MainTest.class.getClassLoader().getResource("eml/testPlain.eml").toURI()).getAbsolutePath(); String[] args = new String[]{ "-o", tmpPdf.getAbsolutePath(), eml }; LogLevel old = Logger.level; Logger.level = LogLevel.Error; Main.main(args); Logger.level = old; assertTrue(tmpPdf.exists()); // assertTrue(tmpPdf.length() > 0); if (!tmpPdf.delete()) { tmpPdf.deleteOnExit(); } }
Example 2
Source File: DirectoryParser.java From bubble with MIT License | 6 votes |
@Override public void parse(File dir) throws IOException { if (!dir.isDirectory()) { throw new IOException("Not a directory: " + dir.getAbsolutePath()); } File[] files = dir.listFiles(); if (files != null) { for (File f : dir.listFiles()) { if (f.isDirectory()) { throw new IOException("Probably not a comic directory"); } if (Utils.isImage(f.getAbsolutePath())) { mFiles.add(f); } } } Collections.sort(mFiles, new NaturalOrderComparator() { @Override public String stringValue(Object o) { return ((File) o).getName(); } }); }
Example 3
Source File: RespawnTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void copyFile(File file, File directory) throws IOException{ File tgt = new File(directory, file.getName()); if (tgt.exists()) { if (!tgt.delete()) { throw new IllegalStateException("Could not delete file " + tgt.getAbsolutePath()); } } final InputStream in = new BufferedInputStream(new FileInputStream(file)); try { final OutputStream out = new BufferedOutputStream(new FileOutputStream(tgt)); try { int i = in.read(); while (i != -1) { out.write(i); i = in.read(); } } finally { IoUtils.safeClose(out); } } finally { IoUtils.safeClose(in); } }
Example 4
Source File: KeyLoader.java From protect with MIT License | 6 votes |
public KeyLoader(final File keyPath, final Set<String> keyNames) throws FileNotFoundException, IOException, NoSuchAlgorithmException, InvalidKeySpecException, CertificateException { this.tlsPublicKeys = new ArrayList<>(keyNames.size()); this.verificationKeys = new ArrayList<>(keyNames.size()); this.encryptionKeys = new ArrayList<>(keyNames.size()); // Load all public keys for (String username : keyNames) { final File publicKeyFile = new File(keyPath, "public-" + username); try (final PemReader reader = new PemReader(new FileReader(publicKeyFile.getAbsolutePath()))) { final PublicKey tlsPublicKey = (PublicKey) Pem.readObject(reader.readPemObject()); this.tlsPublicKeys.add(tlsPublicKey); this.userTlsKeyMap.put(Hex.encodeHexString(tlsPublicKey.getEncoded()), username); this.verificationKeys.add((PublicKey) Pem.readObject(reader.readPemObject())); this.encryptionKeys.add((PublicKey) Pem.readObject(reader.readPemObject())); } } this.tlsKey = null; this.signingKey = null; this.decryptionKey = null; }
Example 5
Source File: OStorageUtils.java From hr with GNU Affero General Public License v3.0 | 6 votes |
public static String getDirectoryPath(String file_type) { File externalStorage = Environment.getExternalStorageDirectory(); String path = externalStorage.getAbsolutePath() + "/Odoo"; File baseDir = new File(path); if (!baseDir.isDirectory()) { baseDir.mkdir(); } if (file_type == null) { file_type = "file"; } if (file_type.contains("image")) { path += "/Images"; } else if (file_type.contains("audio")) { path += "/Audio"; } else { path += "/Files"; } File fileDir = new File(path); if (!fileDir.isDirectory()) { fileDir.mkdir(); } return path; }
Example 6
Source File: DFActorManagerJs.java From dfactor with MIT License | 6 votes |
private boolean _isValidJsFile(File f){ if(f.getName().endsWith(".js")){ //检测是否客户端js if(_lsWebRoot != null && !_lsWebRoot.isEmpty()){ //has config webRoot, ignore client js file String absPath = f.getAbsolutePath(); if(DFSysUtil.getOSType() == DFSysUtil.OS_WINDOWS){ absPath = absPath.replaceAll("\\\\", "/"); } for(String pathWebRoot : _lsWebRoot){ if(absPath.startsWith(pathWebRoot)){ return false; } } } return true; } return false; }
Example 7
Source File: ProjectsComboBox.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void updateItem(File item, boolean empty) { super.updateItem(item, empty); // add/remove separator below "open folder" item if (!empty && item == OPEN_FOLDER && ProjectsComboBox.this.getItems().size() > 1) getStyleClass().add("open-project"); else getStyleClass().remove("open-project"); String text = null; Node graphic = null; if (!empty && item != null) { text = (item == OPEN_FOLDER) ? Messages.get("ProjectsComboBox.openProject") : item.getAbsolutePath(); graphic = closeButton; closeButton.setVisible(item != OPEN_FOLDER); } setText(text); setGraphic(graphic); }
Example 8
Source File: CustomizerSources.java From netbeans with Apache License 2.0 | 5 votes |
private LocalServer initCopyTarget() { // copy target, if any File copyTarget = ProjectPropertiesSupport.getCopySourcesTarget(properties.getProject()); if (copyTarget == null) { return LocalServer.getEmpty(); } FileObject resolvedFO = FileUtil.toFileObject(copyTarget); if (resolvedFO == null) { // target directory doesn't exist?! return new LocalServer(copyTarget.getAbsolutePath()); } return new LocalServer(FileUtil.getFileDisplayName(resolvedFO)); }
Example 9
Source File: ZipFiles.java From beam with Apache License 2.0 | 5 votes |
/** * Unzips the zip file specified by the path and creates the directory structure <i>inside</i> the * target directory. Refuses to unzip files that refer to a parent directory, for security * reasons. * * @param zipFile the source zip-file to unzip * @param targetDirectory the directory to unzip to. If the zip-file contains any subdirectories, * they will be created within our target directory. * @throws IOException the unzipping failed, e.g. because the output was not writable, the {@code * zipFile} was not readable, or contains an illegal entry (contains "..", pointing outside * the target directory) * @throws IllegalArgumentException the target directory is not a valid directory (e.g. does not * exist, or is a file instead of a directory) */ static void unzipFile(File zipFile, File targetDirectory) throws IOException { checkNotNull(zipFile); checkNotNull(targetDirectory); checkArgument( targetDirectory.isDirectory(), "%s is not a valid directory", targetDirectory.getAbsolutePath()); try (ZipFile zipFileObj = new ZipFile(zipFile)) { for (ZipEntry entry : entries(zipFileObj)) { checkName(entry.getName()); File targetFile = new File(targetDirectory, entry.getName()); if (entry.isDirectory()) { if (!targetFile.isDirectory() && !targetFile.mkdirs()) { throw new IOException("Failed to create directory: " + targetFile.getAbsolutePath()); } } else { File parentFile = targetFile.getParentFile(); if (!parentFile.isDirectory() && !parentFile.mkdirs()) { throw new IOException("Failed to create directory: " + parentFile.getAbsolutePath()); } // Write the file to the destination. asByteSource(zipFileObj, entry).copyTo(Files.asByteSink(targetFile)); } } } }
Example 10
Source File: FallbackFileManagerTest.java From c2mon with GNU Lesser General Public License v3.0 | 5 votes |
/** * Prepares the dataTags list that will be used for the tests */ @BeforeClass public static void setUp() throws IOException { final File dataTagFallback = File.createTempFile("DataTagFallback", ".log"); dataTagFallback.deleteOnExit(); // create a FallbackImpl object FallbackImpl fImpl = new FallbackImpl(); fImpl.setObjectData("100142 CP.MEY.TEST13:TEST_STATE false Boolean 2009-01-15 10:06:34.562 0 null 0 I 2009-01-15 10:08:10.8"); data.add(fImpl); fImpl = new FallbackImpl(); fImpl.setObjectData("100143 CP.MEY.TEST14:TEST_STATE false Boolean 2009-01-15 10:06:34.562 0 null 0 I 2009-01-15 10:08:11.235"); data.add(fImpl); fFileManager = new FallbackFileManager(dataTagFallback.getAbsolutePath(), new FallbackImpl()); }
Example 11
Source File: Config.java From offspring with MIT License | 5 votes |
private static File findFileInParent(File parent, String filename) { File file = new File(parent.getAbsolutePath() + File.separator + filename); if (file.exists()) return file; if (parent.getParentFile() != null) return findFileInParent(parent.getParentFile(), filename); return null; }
Example 12
Source File: CropUtil.java From UltimateAndroid with Apache License 2.0 | 5 votes |
public static boolean copyExifRotation(File sourceFile, File destFile) { if (sourceFile == null || destFile == null) return false; try { ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath()); ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath()); exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION)); exifDest.saveAttributes(); return true; } catch (IOException e) { Log.e("Error copying Exif data", e); return false; } }
Example 13
Source File: LocalImageloaderActivity.java From base-imageloader with Apache License 2.0 | 5 votes |
@Override public void selected(ImageFloder floder) { mImgDir = new File(floder.getDir()); mImgs = Arrays.asList(mImgDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(".jpg") || filename.endsWith(".png") || filename.endsWith(".jpeg")) return true; return false; } })); /** * 可以看到文件夹的路径和图片的路径分开保存,极大的减少了内存的消耗; */ mAdapter = new MyAdapter(getApplicationContext(), mImgs, R.layout.grid_item, mImgDir.getAbsolutePath()); mGirdView.setAdapter(mAdapter); // mAdapter.notifyDataSetChanged(); mImageCount.setText(floder.getCount() + "张"); mChooseDir.setText(floder.getName()); mListImageDirPopupWindow.dismiss(); }
Example 14
Source File: FinderLocalAttributesFinderTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testGetCreationDate() throws Exception { assertEquals(-1, new FinderLocalAttributes(new FinderLocal(UUID.randomUUID().toString())).getCreationDate()); final File f = new File(UUID.randomUUID().toString()); f.createNewFile(); FinderLocalAttributes a = new FinderLocalAttributes(new FinderLocal(f.getAbsolutePath())); assertTrue(a.getCreationDate() > 0); f.delete(); }
Example 15
Source File: RunpathTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
final String findElfReader() { String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"}; final String cmd = isSolaris ? "elfdump" : "readelf"; for (String x : paths) { File p = new File(x); File e = new File(p, cmd); if (e.canExecute()) { return e.getAbsolutePath(); } } System.err.println("Warning: no suitable elf reader!"); return null; }
Example 16
Source File: ArchiverHandlerTestCase.java From vespa with Apache License 2.0 | 4 votes |
/** * Log some messages to the handler and verify that they are * written. */ @Test public void testLogging() throws java.io.IOException, InvalidLogFormatException { File tmpDir = temporaryFolder.newFolder(); ArchiverHandler a = new ArchiverHandler(tmpDir.getAbsolutePath(), 1024); for (int i = 0; i < msg.length; i++) { a.handle(msg[i]); } a.close(); // make sure all the log files are there, that all log entries // are accounted for and that they match what we logged. int messageCount = 0; // map of files we've already inspected. this we need to ensure // that we are not inspecting the same files over and over again // so the counts get messed up Set<String> inspectedFiles = new HashSet<String>(); for (int i = 0; i < msg.length; i++) { String name = a.getPrefix(msg[i]) + "-0"; // have we inspected this file before? if (! inspectedFiles.add(name)) { continue; } File f = new File(name); assertTrue(f.exists()); BufferedReader br = new BufferedReader(new FileReader(f)); for (String line = br.readLine(); line != null; line = br.readLine()) { // primitive check if the messages match boolean foundMatch = false; for (int k = 0; k < mStrings.length; k++) { if (mStrings[k].equals(line)) { foundMatch = true; break; } } assertTrue(foundMatch); // try to instantiate messages to ensure that they // are parseable @SuppressWarnings("unused") LogMessage m = LogMessage.parseNativeFormat(line); messageCount++; } br.close(); } // verify that the number of log messages written equals // the number of log messages we have in our test assertEquals(mStrings.length, messageCount); }
Example 17
Source File: OsmFileCacheTileLoader.java From Course_Generator with GNU General Public License v3.0 | 4 votes |
public void setTileCacheDir(String tileCacheDir) { File dir = new File(tileCacheDir); dir.mkdirs(); this.cacheDirBase = dir.getAbsolutePath(); }
Example 18
Source File: PDFView.java From AndroidPDF with Apache License 2.0 | 4 votes |
/** Use a file as the pdf source */ public Configurator fromFile(File file) { if (!file.exists()) throw new FileNotFoundException(file.getAbsolutePath() + "does not exist."); return new Configurator(Uri.fromFile(file)); }
Example 19
Source File: TestCommitterEventHandler.java From big-c with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { File dir = new File(stagingDir); stagingDir = dir.getAbsolutePath(); }
Example 20
Source File: FileStuff.java From proparse with Eclipse Public License 2.0 | 3 votes |
/** * Prepare a target path, based on a specified target path * name plus an original sourcefile name. * @param outputDir The name of the top of the output directory structure. * @param sourceFilename The name of the original sourcefile, used as basis for output filename. * @return The filename that you should use for writing target source to. * We build a target directory structure which resembles the * source code *absolute* path. Why? Because we may have any * number of absolute paths in our PROPATH: * "/u1/my/application,/u2/third/party/library,etc" * It is easiest and most consistent to just use absolute path * for all entries, rather than try to use relative path for some * and be forced to use absolute path for others. * We even include drive letters, because it is possible for developers * to use a PROPATH for version/variant management: * "x:/myapp,y:/myapp" * To avoid really long target directory names, use an output top * directory that is near root, ex: "/temp/out". * We replace ':' (Windows drive letter) with '_', so that we are * always working with a valid name. */ public static String prepareTarget(String outputDir, String sourceFilename) { File sourceFile = new File(sourceFilename); String sourcePath = sourceFile.getAbsolutePath(); File theTarget = new File(outputDir + "/" + sourcePath.replace(':', '_')); String returnName = theTarget.getAbsolutePath(); theTarget = theTarget.getParentFile(); theTarget.mkdirs(); return returnName; }