Find a non-existing file in the same directory using the same name as prefix.

@param file file used for the name and location (it is not read or written).
@return a non-existing file in the same directory using the same name as prefix.
552441
public static File getTempFileFor(File file) {
    File parent = file.getParentFile();
    String name = file.getName();
    File result;
    int index = 0;
    do {
      result = new File(parent, name + "_" + index++);
    }
    while (result.exists());
    return result;
  }
484136
public static String getSuffix(File file) {

        String filename = file.getName();
        int index = filename.lastIndexOf(".");
        if (index != -1) {
            return filename.substring(index + 1);
        }

        return filename;
    }
1316214
public static String getFileExtension(File file) {
        if (file == null) {
            return null;
        }

        String fileName = file.getName();
        int dotPos = fileName.lastIndexOf('.');
        return dotPos == -1 ? null : fileName.substring(dotPos + 1);
    }
851812
public static boolean isFileImportable(File file, String prefix) throws SQLException, FileNotFoundException{
        if (isExtensionWellFormated(file, prefix)) {
            if (file.exists()) {
                return true;
            } else {
                throw new FileNotFoundException("The following file does not exists:\n" + file.getPath());
            }
        } else {
            throw new SQLException("Please use " + prefix + " extension.");
        }
    }
1172339
public static String asPath(File file) {
        if (file == null) {
            return null;
        }
        return asPath(file.getPath());
    }
911626
public static Exception checkFile(final File file)
	{
		Exception ex = null;
		String error = null;
		// check if the file does not exists...
		if (!file.exists())
		{
			error = "The " + file + " does not exists.";
			ex = new FileDoesNotExistException(error);
			return ex;
		}
		// check if the file is not a directory...
		if (!file.isDirectory())
		{
			error = "The " + file + " is not a directory.";
			ex = new FileIsNotADirectoryException(error);
			return ex;
		}

		final File[] ff = file.listFiles();
		// If the file is null
		if (ff == null)
		{ // it is security restricted
			error = "The " + file + " could not list the content.";
			ex = new DirectoryHasNoContentException(error);
		}
		return ex;
	}
840836
public String getNewCalendarPath(File file)
    {
        StringTokenizer st = new StringTokenizer(file.getName());
        int iPlace = 0, iMonth = 0, iYear = 0;
        while (st.hasMoreTokens())
        {
            String strToken = st.nextToken();
            if (strToken.length() > 2)
                break;  // Not a date
            if (!Utility.isNumeric(strToken))
                break;  // Not a date
            if (strToken.indexOf('.') != -1)
                break;
            int iNumber = Integer.parseInt(strToken);
            iPlace++;
            if (iPlace == 1)
            { // Month
                if ((iNumber < 1) || (iNumber > 12))
                    break;  // Invalid month
                iMonth = iNumber;
            }
            else if (iPlace == 2)
            { // day
                if ((iNumber < 1) || (iNumber > 31))
                    break;  // Invalid day
            }
            else if (iPlace == 3)
            { // Year
                if ((iNumber < 1) || (iNumber > 2020))
                    break;  // Invalid year
                iYear = iNumber;
                if (iYear <= 20)
                    iYear = iYear + 2000;
                return Integer.toString(iYear) + '/' + m_rgstrMonths[iMonth - 1];
            }
        }
        return null;    // Not formatted correctly
    }
259691
public static boolean isFile(Resource file) {
	if (file.exists()) return file.isFile();
	Resource parent = file.getParentResource();
	return parent.mkdirs() && file.createNewFile();
    }
763898
public static List<File> findAllFile(File file) {
        if (file == null || !file.exists()) {
            return Collections.emptyList();
        }

        if (file.isFile()) {
            return Collections.singletonList(file);
        }

        List<File> fileList = new ArrayList<>();
        File[] files = file.listFiles();
        for (File f : files) {
            fileList.addAll(findAllFile(f));
        }

        return fileList;
    }
271073
public static String getExtension(String file)
    {
        Check.notNull(file);

        String ext = Constant.EMPTY_STRING;
        final int i = file.lastIndexOf(Constant.DOT);
        if (i >= 0 && i < file.length() - 1)
        {
            ext = file.substring(i + 1).toLowerCase(Locale.ENGLISH);
        }
        return ext;
    }
721277
public static SObject of(String key, File file) {
        if (file.canRead() && file.isFile()) {
            SObject sobj = new FileSObject(key, file);
            String fileName = file.getName();
            sobj.setAttribute(ATTR_FILE_NAME, file.getName());
            String fileExtension = S.fileExtension(fileName);
            MimeType mimeType = MimeType.findByFileExtension(fileExtension);
            String type = null != mimeType ? mimeType.type() : null;
            sobj.setAttribute(ATTR_CONTENT_TYPE, type);
            sobj.setAttribute(ATTR_CONTENT_LENGTH, S.string(file.length()));
            return sobj;
        } else {
            return getInvalidObject(key, new IOException("File is a directory or not readable"));
        }
    }
106061
public ContentInfo findMatch(File file) throws IOException {
		int readSize = fileReadSize;
		if (!file.exists()) {
			throw new IOException("File does not exist: " + file);
		}
		if (!file.canRead()) {
			throw new IOException("File is not readable: " + file);
		}
		long length = file.length();
		if (length <= 0) {
			return ContentInfo.EMPTY_INFO;
		}
		if (length < readSize) {
			readSize = (int) length;
		}
		byte[] bytes = new byte[readSize];
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(file);
			int numRead = fis.read(bytes);
			if (numRead <= 0) {
				return ContentInfo.EMPTY_INFO;
			}
			if (numRead < bytes.length) {
				bytes = Arrays.copyOf(bytes, numRead);
			}
		} finally {
			closeQuietly(fis);
		}
		return findMatch(bytes);
	}
672365
public final boolean isFileExcludedByExtension(@Nullable final File file) {
    return file == null || !file.isFile() || this.excludeExtensions.contains(PreprocessorUtils.getFileExtension(file));
  }
648078
public static String readTextFile(File file) {
        try {
            return readTextFile(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
149159
public boolean exists(final File file) {
        if (System.getSecurityManager() == null)
            return file.exists();
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            @Override
            public Boolean run() {
                return file.exists() ? Boolean.TRUE : Boolean.FALSE;
            }
        }, controlContext).booleanValue();
    }
736007
private static InputStream getFileAsInputStream(String file) throws InitializationException {
		if (file == null) {
			throw new NullPointerException("File is null");
		}
		try {
			return new FileInputStream(new File(file));
		} catch (FileNotFoundException e) {
			throw new InitializationException("File not found: " + file);
		}
	}
1041206
private String getSourceSetNameFromFile(File file) {
    Path absolutePath = Paths.get(file.getAbsolutePath());
    Path basePath = Paths.get(task.getProject().file("src").getAbsolutePath());

    return basePath.relativize(absolutePath).toString().split(Matcher.quoteReplacement(File.separator))[0];
  }