return diffrents of one file to a other if first is child of second otherwise return null

@param file file to search
@param dir directory to search
197195
public static String getPathToChild(Resource file, Resource dir) {
	if (dir == null || !file.getResourceProvider().getScheme().equals(dir.getResourceProvider().getScheme())) return null;
	boolean isFile = file.isFile();
	String str = "/";
	while (file != null) {
	    if (file.equals(dir)) {
		if (isFile) return str.substring(0, str.length() - 1);
		return str;
	    }
	    str = "/" + file.getName() + str;
	    file = file.getParentResource();
	}
	return null;
    }
231081
public static boolean contentEquals(File file1, File file2) throws IORuntimeException {
		boolean file1Exists = file1.exists();
		if (file1Exists != file2.exists()) {
			return false;
		}

		if (false == file1Exists) {
			// 两个文件都不存在，返回true
			return true;
		}

		if (file1.isDirectory() || file2.isDirectory()) {
			// 不比较目录
			throw new IORuntimeException("Can't compare directories, only files");
		}

		if (file1.length() != file2.length()) {
			// 文件长度不同
			return false;
		}

		if (equals(file1, file2)) {
			// 同一个文件
			return true;
		}

		InputStream input1 = null;
		InputStream input2 = null;
		try {
			input1 = getInputStream(file1);
			input2 = getInputStream(file2);
			return IoUtil.contentEquals(input1, input2);

		} finally {
			IoUtil.close(input1);
			IoUtil.close(input2);
		}
	}
50982
public boolean filterDirectory(File file)
    {
        if ("CVS".equalsIgnoreCase(file.getName()))
            return false;
        if (file.getName().startsWith("."))
            return false;
        return true;    // By default, process all directories
    }
1320874
public void setDirectory( File file ) {

		List<File> roots = null;
		if( file == null ) {
			// Create a list of roots with something in them.  Windows list to list non-existant devices
			roots = new ArrayList<>(Arrays.asList(File.listRoots()));
			for (int i = roots.size()-1; i >= 0; i--) {
				File[]files = roots.get(i).listFiles();
				if( files == null || files.length == 0) {
					roots.remove(i);
				}
			}

			if( roots.size() == 1 ) {
				file = roots.get(0);
				roots = null;
			}
		}

		if( roots == null ) {
			setDirectoryNormal(file);
		} else {
			// Present the user with a list of file system roots
			fileName.setText("");

			listModel.clear();
			for (File f : roots) {
				listModel.addElement(f);
			}

			directoryPath.removeActionListener(directoryListener);
			directoryPath.removeAllItems();
			directoryPath.addActionListener(directoryListener);

			listener.handleSelectedFile(null);
		}
	}
446480
public static List<File> findAllFiles(final File dir, final String fileSearchPattern)
	{
		final List<File> foundFiles = new ArrayList<>();
		// Get all files
		final File[] children = dir.getAbsoluteFile().listFiles();
		if (children == null || children.length < 1)
		{
			return foundFiles;
		}
		for (final File element : children)
		{
			// if the entry is a directory
			if (element.isDirectory())
			{ // then
				// find recursively in the directory and put it in a List.
				final List<File> foundedFiles = findAllFiles(element, fileSearchPattern);
				// Put the founded files in the main List.
				foundFiles.addAll(foundedFiles);
			}
			else
			{
				// entry is a file
				final String filename = element.getName();
				if (filename.matches(fileSearchPattern))
				{
					foundFiles.add(element.getAbsoluteFile());
				}
			}
		}
		return foundFiles;
	}
1141275
public static boolean isEmpty(File file) {
		if (null == file) {
			return true;
		}

		if (file.isDirectory()) {
			String[] subFiles = file.list();
			if (ArrayUtil.isEmpty(subFiles)) {
				return true;
			}
		} else if (file.isFile()) {
			return file.length() <= 0;
		}

		return false;
	}
814308
public final void dirRemove(File dir) throws IOException {
		if (dir != null) {
			getLog().debug("Deleting tree: " + dir.toString()); //$NON-NLS-1$
			final LinkedList<File> candidates = new LinkedList<>();
			candidates.add(dir);
			File[] children;
			final BuildContext buildContext = getBuildContext();
			while (!candidates.isEmpty()) {
				final File f = candidates.getFirst();
				getLog().debug("Scanning: " + f); //$NON-NLS-1$
				if (f.isDirectory()) {
					children = f.listFiles();
					if (children != null && children.length > 0) {
						// Non empty directory
						for (final File c : children) {
							getLog().debug("Discovering: " + c); //$NON-NLS-1$
							candidates.push(c);
						}
					} else {
						// empty directory
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						candidates.removeFirst();
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				} else {
					// not a directory
					candidates.removeFirst();
					if (f.exists()) {
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				}
			}
			getLog().debug("Deletion done"); //$NON-NLS-1$
		}
	}
682859
public static File noDirectory(File file) {
		Validate.exists(file);
		if(file.isDirectory())
			throw new ParameterException("\""+file+"\" is a directory!");
		return file;
	}
361142
protected static File findRawDir(File dir) {
		for (int i = 0; dir != null && i < 20; i++) {
			File rawDir = findResRawDir(dir);
			if (rawDir != null) {
				return rawDir;
			}
			dir = dir.getParentFile();
		}
		return null;
	}
726436
@CheckForNull
  public String relativePath(Path dir, Path file) {
    Path baseDir = dir.normalize();
    Path path = file.normalize();
    if (!path.startsWith(baseDir)) {
      return null;
    }
    try {
      Path relativized = baseDir.relativize(path);
      return FilenameUtils.separatorsToUnix(relativized.toString());
    } catch (IllegalArgumentException e) {
      return null;
    }
  }
895287
public static void createParentDirectoryIfNecessary(final File file) {
        final File parentDirectory = file.getParentFile();
        if (parentDirectory == null || parentDirectory.mkdirs() || parentDirectory.exists()) {
            return;
	}
        throw new SdkClientException("Unable to create directory in the path: " + parentDirectory.getAbsolutePath());
    }
408859
public final Collection<File> findFiles(File directory, FileFilter filter) {
		final Collection<File> files = new ArrayList<>();
		findFiles(directory, filter, files);
		return files;
	}
471083
private ArrayList<String> getFiles(String dir, String subDir) {
    ArrayList<String> files = new ArrayList<>();
    String fullDir = subDir == null ? dir : dir + File.separator + subDir;
    File[] listOfFiles = (new File(fullDir)).listFiles();
    if (listOfFiles != null) {
      for (File file : listOfFiles) {
        String fullName = subDir == null ? file.getName() : subDir + File.separator + file.getName();
        if (file.isFile()) {
          files.add(fullName);
        } else if (file.isDirectory()) {
          files.addAll(getFiles(dir, fullName));
        }
      }
    }
    return files;
  }
1080941
private static synchronized int deleteRecursively(File directory) {
		int deleted = 0;
		if(directory.isDirectory()) {
			File[] contents = directory.listFiles();
			for(File file : contents) {
				deleted += deleteRecursively(file);
			}
		} else {
			deleted++;
		}
		directory.delete();
		return deleted;
	}
497019
public static List<File> listDirectories( File root ) {

		List<File> result = new ArrayList<> ();
		File[] files = root.listFiles( new DirectoryFileFilter());
		if( files != null )
			result.addAll( Arrays.asList( files ));

		Collections.sort( result, new FileNameComparator());
		return result;
	}
699643
protected void scanDir(final File file, final String path) {
        for ( final File child: file.listFiles() ) {
            final String newPath = (path==null ? child.getName() : path + '/' + child.getName() );
            if ( child.isDirectory() ) {
                scanDir(child, newPath);
            }
            else {
                handleItem(newPath);
            }
        }
    }
1298403
private List<File> listFiles(File file, List<File> files) {
        File[] children = file.listFiles();
        
        if (children != null) {
            for (File child : children) {
                files.add(child);
                listFiles(child, files);
            }
        }
        
        return files;
    }