本文整理了Java中java.io.File.equals()
方法的一些代码示例,展示了File.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.equals()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:equals
[英]Compares obj to this file and returns true if they represent the same object using a path specific comparison.
[中]
代码示例来源:origin: libgdx/libgdx
protected void processDir (Entry entryDir, ArrayList<Entry> files) {
if (!entryDir.inputFile.equals(inputDir.inputFile) && new File(entryDir.inputFile, "pack.json").exists()) {
files.clear();
return;
}
if (!countOnly) ignoreDirs.add(entryDir.inputFile);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* To be kept in sync with {@link FilePathVF#computeRelativePathToRoot()}
*/
private String computeRelativePathToRoot(){
if (this.root.equals(this.f)) {
return "";
}
Deque<String> relativePath = new LinkedList<>();
File current = this.f;
while (current != null && !current.equals(this.root)) {
relativePath.addFirst(current.getName());
current = current.getParentFile();
}
return String.join(File.separator, relativePath) + File.separator;
}
}
代码示例来源:origin: skylot/jadx
private static boolean isInSubDirectoryInternal(File baseDir, File canonFile) {
if (canonFile == null) {
return false;
}
if (canonFile.equals(baseDir)) {
return true;
}
return isInSubDirectoryInternal(baseDir, canonFile.getParentFile());
}
代码示例来源:origin: android-hacker/VirtualXposed
public static boolean isSymlink(File file) throws IOException {
if (file == null)
throw new NullPointerException("File must not be null");
File canon;
if (file.getParent() == null) {
canon = file;
} else {
File canonDir = file.getParentFile().getCanonicalFile();
canon = new File(canonDir, file.getName());
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}
代码示例来源:origin: redisson/redisson
/**
* Creates a new iterator representation for all files within a folder.
*
* @param folder The root folder.
*/
protected FolderIterator(File folder) {
files = new LinkedList<File>(Collections.singleton(folder));
File candidate;
do {
candidate = files.removeFirst();
File[] file = candidate.listFiles();
if (file != null) {
files.addAll(0, Arrays.asList(file));
}
} while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME))));
}
代码示例来源:origin: redisson/redisson
String name = element.getName();
if (!name.endsWith("/")) {
File target = new File(folder, name), resolved = element.resolveAs(File.class);
if (!target.getCanonicalPath().startsWith(folder.getCanonicalPath())) {
throw new IllegalArgumentException(target + " is not a subdirectory of " + folder);
} else if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) {
throw new IOException("Could not create directory: " + target.getParent());
} else if (DISPATCHER.isAlive() && resolved != null && !resolved.equals(target)) {
DISPATCHER.copy(resolved, target);
} else if (!target.equals(resolved)) {
InputStream inputStream = element.getInputStream();
try {
代码示例来源:origin: Meituan-Dianping/walle
@Override
public void parse() {
final File inputFile = files.get(0);
File outputFile = null;
if (files.size() == 2) {
outputFile = files.get(1);
} else {
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channel + "." + extension;
outputFile = new File(inputFile.getParent(), newName);
}
if (inputFile.equals(outputFile)) {
try {
ChannelWriter.put(outputFile, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
} else {
try {
FileUtils.copyFile(inputFile, outputFile);
ChannelWriter.put(outputFile, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: apache/geode
private static String tailSystemLog(DistributionConfig sc) throws IOException {
File logFile = sc.getLogFile();
if (logFile == null || logFile.equals(new File(""))) {
return null;
}
if (!logFile.isAbsolute()) {
logFile = new File(logFile.getAbsolutePath());
}
return tailSystemLog(logFile);
}
}
代码示例来源:origin: org.apache.ant/ant
if (!srcFile.exists()) {
throw new BuildException("src " + srcFile.toString()
+ " does not exist.", getLocation());
if (srcFile.equals(destFile)) {
log("Warning: src == dest", Project.MSG_WARN);
} catch (IOException ioe) {
throw new BuildException(
"Error copying file: " + srcFile.getAbsolutePath()
+ " due to " + ioe.getMessage());
代码示例来源:origin: jmxtrans/jmxtrans
/**
* Are we a file and a JSON or YAML file?
*/
private boolean isProcessConfigFile(File file) {
if (this.configuration.getProcessConfigDirOrFile().isFile()) {
return file.equals(this.configuration.getProcessConfigDirOrFile());
}
// If the file doesn't exist anymore, treat it as a regular file (to handle file deletion events)
if(file.exists() && !file.isFile()) {
return false;
}
final String fileName = file.getName();
return !fileName.startsWith(".") && (fileName.endsWith(".json") || fileName.endsWith(".yml") || fileName.endsWith(".yaml"));
}
代码示例来源:origin: citerus/dddsample-core
@Override
public void afterPropertiesSet() throws Exception {
if (uploadDirectory.equals(parseFailureDirectory)) {
throw new Exception("Upload and parse failed directories must not be the same directory: " + uploadDirectory);
}
if (!uploadDirectory.exists()) {
uploadDirectory.mkdirs();
}
if (!parseFailureDirectory.exists()) {
parseFailureDirectory.mkdirs();
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Are the two File instances pointing to the same object on the
* file system?
*
* @param f1 File
* @param f2 File
* @return boolean
* @throws IOException if file name canonicalization fails
* @since Ant 1.8.2
*/
public boolean areSame(File f1, File f2) throws IOException {
if (f1 == null && f2 == null) {
return true;
}
if (f1 == null || f2 == null) {
return false;
}
File f1Normalized = normalize(f1.getAbsolutePath());
File f2Normalized = normalize(f2.getAbsolutePath());
return f1Normalized.equals(f2Normalized)
|| f1Normalized.getCanonicalFile().equals(f2Normalized
.getCanonicalFile());
}
代码示例来源:origin: oracle/opengrok
File f1 = parent.getCanonicalFile();
File f2 = file.getCanonicalFile();
if (f1.equals(f2)) {
LOGGER.log(Level.INFO, "Skipping links to itself...: {0} {1}",
new Object[]{parent.getAbsolutePath(), file.getAbsolutePath()});
return false;
while ((t1 = t1.getParentFile()) != null) {
if (f2.equals(t1)) {
LOGGER.log(Level.INFO, "Skipping links to parent...: {0} {1}",
new Object[]{parent.getAbsolutePath(), file.getAbsolutePath()});
return false;
代码示例来源:origin: Sable/soot
public void add(SootClass c) {
if (c.isPhantom()) {
return;
}
addAsClassDefItem(c);
// save original APK for this class, needed to copy all the other files
// inside
Map<String, File> dexClassIndex = SourceLocator.v().dexClassIndex();
if (dexClassIndex == null) {
return; // no dex classes were loaded
}
File sourceForClass = dexClassIndex.get(c.getName());
if (sourceForClass == null || sourceForClass.getName().endsWith(".dex")) {
return; // a class was written that was not a dex class or the class
// originates from a .dex file, not an APK
}
if (originalApk != null && !originalApk.equals(sourceForClass)) {
throw new CompilationDeathException("multiple APKs as source of an application are not supported");
}
originalApk = sourceForClass;
}
代码示例来源:origin: stackoverflow.com
public static boolean isSymlink(File file) throws IOException {
if (file == null)
throw new NullPointerException("File must not be null");
File canon;
if (file.getParent() == null) {
canon = file;
} else {
File canonDir = file.getParentFile().getCanonicalFile();
canon = new File(canonDir, file.getName());
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}
代码示例来源:origin: libgdx/libgdx
protected void processDir (Entry entryDir, ArrayList<Entry> files) {
if (!entryDir.inputFile.equals(inputDir.inputFile) && new File(entryDir.inputFile, "pack.json").exists()) {
files.clear();
return;
}
if (!countOnly) ignoreDirs.add(entryDir.inputFile);
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
@SuppressFBWarnings(value = "IT_NO_SUCH_ELEMENT", justification = "Exception is thrown by invoking removeFirst on an empty list.")
public Element next() {
try {
return new Element.ForFile(folder, files.removeFirst());
} finally {
while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME)))) {
File folder = files.removeFirst();
File[] file = folder.listFiles();
if (file != null) {
files.addAll(0, Arrays.asList(file));
}
}
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
/**
* Grab the rather voluminous vertical datum files from the OTP web server and save them in the NED cache directory.
*/
private void fetchDatum() throws Exception {
LOG.info("Attempting to fetch datum files from OTP project web server...");
URL datumUrl = new URL("http://dev.opentripplanner.org/resources/datum.zip");
ZipInputStream zis = new ZipInputStream(datumUrl.openStream());
/* Silly boilerplate because Java has no simple unzip-to-directory function. */
for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
if (entry.isDirectory()) {
throw new RuntimeException("ZIP files containing directories are not supported");
}
File file = new File(cacheDirectory, entry.getName());
if (!file.getParentFile().equals(cacheDirectory)) {
throw new RuntimeException("ZIP files containing directories are not supported");
}
LOG.info("decompressing {}", file);
OutputStream os = new FileOutputStream(file);
ByteStreams.copy(zis, os);
os.close();
}
zis.close();
LOG.info("Done.");
}
代码示例来源:origin: apache/incubator-druid
final File outDir = new File(baseStorageDir, this.getStorageDir(segment, useUniquePath));
if (dataSegmentFile.equals(outDir)) {
long size = 0;
for (File file : dataSegmentFile.listFiles()) {
final File tmpOutDir = new File(baseStorageDir, makeIntermediateDir());
log.info("Creating intermediate directory[%s] for segment[%s]", tmpOutDir.toString(), segment.getId());
FileUtils.forceMkdir(tmpOutDir);
final File tmpIndexFile = new File(tmpOutDir, INDEX_FILENAME);
final long size = compressSegment(dataSegmentFile, tmpIndexFile);
final File indexFileTarget = new File(outDir, tmpIndexFile.getName());
final File descriptorFileTarget = new File(outDir, tmpDescriptorFile.getName());
代码示例来源:origin: twosigma/beakerx
private String createGroovyClassName(File root, File file) {
StringBuffer sb = new StringBuffer();
String fileName = file.getName();
sb.append(fileName.substring(0, fileName.lastIndexOf(".groovy")));
file = file.getParentFile();
while (file != null && !file.equals(root)) {
sb.insert(0, '.').insert(0, file.getName());
file = file.getParentFile();
}
return sb.toString();
}
内容来源于网络,如有侵权,请联系作者删除!