java.io.File#getAbsolutePath ( )源码实例Demo

下面列出了java.io.File#getAbsolutePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: markdown-writer-fx   文件: ProjectsComboBox.java
@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);
}
 
源代码2 项目: eml-to-pdf-converter   文件: MainTest.java
@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();
	}
}
 
源代码3 项目: dfactor   文件: DFActorManagerJs.java
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;
}
 
源代码4 项目: hr   文件: OStorageUtils.java
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;
}
 
源代码5 项目: protect   文件: KeyLoader.java
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;
}
 
源代码6 项目: wildfly-core   文件: RespawnTestCase.java
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);
    }
}
 
源代码7 项目: bubble   文件: DirectoryParser.java
@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();
        }
    });
}
 
源代码8 项目: c2mon   文件: FallbackFileManagerTest.java
/**
 * 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());
}
 
源代码9 项目: TencentKona-8   文件: RunpathTest.java
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;
}
 
源代码10 项目: netbeans   文件: CustomizerSources.java
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));
}
 
源代码11 项目: beam   文件: ZipFiles.java
/**
 * 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));
      }
    }
  }
}
 
源代码12 项目: offspring   文件: Config.java
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;
}
 
源代码13 项目: UltimateAndroid   文件: CropUtil.java
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;
    }
}
 
@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();

}
 
@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();
}
 
源代码16 项目: big-c   文件: TestCommitterEventHandler.java
@BeforeClass
public static void setup() {    
  File dir = new File(stagingDir);
  stagingDir = dir.getAbsolutePath();
}
 
源代码17 项目: AndroidPDF   文件: PDFView.java
/** 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));
}
 
源代码18 项目: vespa   文件: ArchiverHandlerTestCase.java
/**
 * 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);
}
 
源代码19 项目: Course_Generator   文件: OsmFileCacheTileLoader.java
public void setTileCacheDir(String tileCacheDir) {
	File dir = new File(tileCacheDir);
	dir.mkdirs();
	this.cacheDirBase = dir.getAbsolutePath();
}
 
源代码20 项目: proparse   文件: FileStuff.java
/**
 * 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;
}