下面列出了java.io.File#getAbsolutePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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();
}
}
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;
}
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;
}
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;
}
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);
}
}
@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();
}
});
}
/**
* 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());
}
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;
}
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));
}
/**
* 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));
}
}
}
}
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;
}
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();
}
@BeforeClass
public static void setup() {
File dir = new File(stagingDir);
stagingDir = dir.getAbsolutePath();
}
/** 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));
}
/**
* 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);
}
public void setTileCacheDir(String tileCacheDir) {
File dir = new File(tileCacheDir);
dir.mkdirs();
this.cacheDirBase = dir.getAbsolutePath();
}
/**
* 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;
}