Java Code Examples for java.io.File.isFile()

The following are Jave code examples for showing how to use isFile() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: phoenix.webui.framework   File: Phoenix.java   View Source Code Vote up 6 votes
/**
 * 从操作系统路径中加载配置文件
 * @param filePath filePath
 * @throws IOException  IOException
 * @throws FileNotFoundException  FileNotFoundException
 * @throws DocumentException  DocumentException
 * @throws SAXException SAXException
 */
public void readFromSystemPath(String filePath) throws FileNotFoundException, 
	IOException, DocumentException, SAXException
{
	configFile = new File(filePath);
	if(!configFile.isFile())
	{
		throw new ConfigException(String.format("Target file [%s] is not a file.", filePath), "");
	}
	else if(!filePath.endsWith(".xml"))
	{
		logger.warn("Target file [%s] is not end with .xml", filePath);
	}
	
	try(InputStream configInput = new FileInputStream(configFile))
	{
		read(configInput);
	}
}
 
Example 2
Project: qpboc-kata   File: EMVParam.java   View Source Code Vote up 6 votes
public void clearAids()
{
    mAidList.clear();
    max_qpboc_offline_limit = 0;
    max_qpboc_trans_limit = 0;
    max_qpboc_cvm_limit = 0;

    String path = mDataPath + "/" + EMVAid._aids_folder;

    File file = new File(path);
    File[] aidList = file.listFiles();

    if(aidList == null) return;

    LogUtil.i(TAG,"" + path + "files count = " + aidList.length);

    for (File f : aidList) {
        if (f.isFile()) {
            LogUtil.i(TAG,"Delete Aid - " + f.getAbsolutePath());
            f.delete();
        }
    }
}
 
Example 3
Project: IntelliJ-codestyle-sync   File: CodeStyleManager.java   View Source Code Vote up 6 votes
private void checkForExistingCodestyles() {
    File[] files = new File(getCodestylePath()).listFiles();

    // File is not a directory
    if(files == null) {
        return;
    }

    ArrayList<File> copyFiles = new ArrayList<>();
    for (File file : files) {
        if (file.isFile() && isXMLFileExtension(file.getName())) {
            copyFiles.add(file);
        }
    }
    copyFiles(copyFiles);
}
 
Example 4
Project: incubator-netbeans   File: Workspace.java   View Source Code Vote up 5 votes
public Variable(String name, String location) {
    this.name = name;
    this.location = location;
    File f = new File(location);
    fileVar = f.exists() && f.isFile();
    if (fileVar) {
        file = f.getName();
        this.location = f.getParentFile().getAbsolutePath();
    }
}
 
Example 5
Project: WebPLP   File: ApplicationSettings.java   View Source Code Vote up 5 votes
/**
 * Attempts to load the settings file from the file parameter.
 * <p>
 * NOTE: This will load the default settings configuration if it fails to load.
 *
 * @param file
 * 		settings file
 *
 * @return True if successfully loaded file, false otherwise.
 */
public static final boolean loadFromFile( File file )
{
	if ( !file.isFile() )
	{
		loadFromDefaultSettings();
		return false;
	}

	try
	{
		String fileContents = FileUtils.readFileToString(file);
		JSONObject jsonFile = new JSONObject(fileContents);

		parseJSONSettings(jsonFile, "");

		if ( settings.isEmpty() )
		{
			loadFromDefaultSettings();
			return false;
		} else
			return true;
	}
	catch ( IOException e )
	{
		loadFromDefaultSettings();
		return false;
	}
}
 
Example 6
Project: ramus   File: WebStartClient.java   View Source Code Vote up 5 votes
private void loadLibs(File[] fs, List<File> al) {
    for (int i = 0; i < fs.length; i++) {
        File c = fs[i];
        if (c.isFile()) {
            String name = c.getName().toLowerCase();
            if ((name.endsWith(".jar")) && (c.isFile())) {
                al.add(c);
            }
        } else if ((c.isDirectory()) && (!c.getName().equals(".."))
                && (!c.getName().equals("."))) {
            loadLibs(c.listFiles(), al);
        }
    }
}
 
Example 7
Project: AndroidBasicLibs   File: PackageUtil.java   View Source Code Vote up 5 votes
/**
 * 调用系统安装应用
 */
public static boolean install(Context context, File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return false;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
    return true;
}
 
Example 8
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 5 votes
/** Tries to set permissions on preferences storage file to -rw------- */
public static void goMinusR(Preferences p) {
    File props = new File(Places.getUserDirectory(), ("config/Preferences" + p.absolutePath()).replace('/', File.separatorChar) + ".properties");
    if (props.isFile()) {
        props.setReadable(false, false); // seems to be necessary, not sure why
        props.setReadable(true, true);
        LOG.log(Level.FINE, "chmod go-r {0}", props);
    } else {
        LOG.log(Level.FINE, "no such file to chmod: {0}", props);
    }
}
 
Example 9
Project: openjdk-jdk10   File: JavacState.java   View Source Code Vote up 5 votes
private static void recurse(File dir, Set<File> foundFiles) {
    for (File f : dir.listFiles()) {
        if (f.isFile()) {
            foundFiles.add(f);
        } else if (f.isDirectory()) {
            recurse(f, foundFiles);
        }
    }
}
 
Example 10
Project: xlight_android_native   File: FileUtils.java   View Source Code Vote up 5 votes
public static void deleteDir(String path) {
	File dir = new File(path);
	if (dir == null || !dir.exists() || !dir.isDirectory())
		return;
	
	for (File file : dir.listFiles()) {
		if (file.isFile())
			file.delete(); // 删除所有文件
		else if (file.isDirectory())
			deleteDir(path); // 递规的方式删除文件夹
	}
	dir.delete();// 删除目录本身
}
 
Example 11
Project: Backmemed   File: Shaders.java   View Source Code Vote up 4 votes
static ArrayList listOfShaders()
{
    ArrayList<String> arraylist = new ArrayList();
    arraylist.add(packNameNone);
    arraylist.add(packNameDefault);

    try
    {
        if (!shaderpacksdir.exists())
        {
            shaderpacksdir.mkdir();
        }

        File[] afile = shaderpacksdir.listFiles();

        for (int i = 0; i < afile.length; ++i)
        {
            File file1 = afile[i];
            String s = file1.getName();

            if (file1.isDirectory())
            {
                File file2 = new File(file1, "shaders");

                if (file2.exists() && file2.isDirectory())
                {
                    arraylist.add(s);
                }
            }
            else if (file1.isFile() && s.toLowerCase().endsWith(".zip"))
            {
                arraylist.add(s);
            }
        }
    }
    catch (Exception var6)
    {
        ;
    }

    return arraylist;
}
 
Example 12
Project: aos-FileCoreLibrary   File: FileManagerCore.java   View Source Code Vote up 4 votes
public int[] getDirectoryContent(File file, String filter) {
    boolean hasFilter = false;
    int files = 0;
    int directories = 0;

    if (filter != null) {
        hasFilter = true;
    }

    File[] listFiles = file.listFiles();
    if (listFiles != null) {
        for (File f : listFiles) {
            if (f.isHidden())
                continue;
            if (f.isFile()) {
                if (!filePathsFiltered.contains(f.getPath())) {
                    if (hasFilter) {
                        String fullName = f.getName();
                        int dotPos = fullName.lastIndexOf('.');
                        if (dotPos >= 0 && dotPos < fullName.length()) {
                            String mimeType = MimeUtils.guessMimeTypeFromExtension(fullName.substring(dotPos + 1).toLowerCase()); 
                            if (mimeType != null){
                                String [] filters = filter.split("\\|\\|");
                                for(String filt: filters){
                                    if(mimeType.startsWith(filt)&&!filt.isEmpty()){
                                        files++;
                                    }

                                }
                            }


                        }
                    } else {
                        files++;
                    }
                }
            } else if (!dirNamesFiltered.contains(f.getName())
                    && !dirPathsFiltered.contains(f.getPath()))
                directories++;
        }
    }

    return new int[] {
            directories, files
    };
}
 
Example 13
Project: WeiXing_xmu-2016-MrCode   File: Center_Vector_Create.java   View Source Code Vote up 4 votes
public static Map readCsvFile(String filePath) {
	try {
		Map userMap = new HashMap();
		int i = 0;
		int row = 0;
		String username = "";
		String geo = "";
		String room = "";
		String encoding = "GBK";
		File file = new File(filePath);
		if (file.isFile() && file.exists()) {
			InputStreamReader read = new InputStreamReader(new DataInputStream(new FileInputStream(file)),
					encoding);
			BufferedReader bufferedReader = new BufferedReader(read);
			String lineTxt = null;
			while ((lineTxt = bufferedReader.readLine()) != null) {
				row++;
				String[] lineArr = lineTxt.split(",");
				if (lineTxt.contains("order")) {
					username = lineArr[0];
				} else if (lineTxt.contains("geog")) {
					if (lineArr.length <= 6) {
						for (i = 1; i < lineArr.length; ++i) {
							geo = geo + "," + lineArr[i];
						}
						for (i = 1; i <= 6 - lineArr.length; ++i) {
							geo = geo + "," + "0";
						}
					} else {
						for (i = lineArr.length - 5; i <= lineArr.length - 1; ++i) {
							geo = geo + "," + lineArr[i];
						}
					}
					geo = geo.substring(1);
				} else if (lineTxt.contains("room")) {
					for (i = 1; i < lineArr.length; ++i) {
						room = room + "," + lineArr[i];
					}
					room = room.substring(1);
				}
				if (row % 3 == 0) {
					userMap.put(username, geo + "\t" + room);
					geo = "";
					room = "";
				}
			}
			read.close();
			return userMap;
		} else {
			System.out.println("�Ҳ���ָ�����ļ�");
			return null;
		}
	} catch (Exception e) {
		System.out.println("��ȡ�ļ����ݳ���");
		e.printStackTrace();
		return null;
	}
}
 
Example 14
Project: javaide   File: ApkBuilder.java   View Source Code Vote up 4 votes
/**
 * Adds the native libraries from the top native folder.
 * The content of this folder must be the various ABI folders.
 *
 * This may or may not copy gdbserver into the apk based on whether the debug mode is set.
 *
 * @param nativeFolder the native folder.
 *
 * @throws ApkCreationException if an error occurred
 * @throws SealedApkException if the APK is already sealed.
 * @throws DuplicateFileException if a file conflicts with another already added to the APK
 *                                   at the same location inside the APK archive.
 *
 * @see #setDebugMode(boolean)
 */
public void addNativeLibraries(File nativeFolder)
        throws ApkCreationException, SealedApkException, DuplicateFileException {
    if (mIsSealed) {
        throw new SealedApkException("APK is already sealed");
    }

    if (!nativeFolder.isDirectory()) {
        // not a directory? check if it's a file or doesn't exist
        if (nativeFolder.exists()) {
            throw new ApkCreationException("%s is not a folder", nativeFolder);
        } else {
            throw new ApkCreationException("%s does not exist", nativeFolder);
        }
    }

    File[] abiList = nativeFolder.listFiles();

    verbosePrintln("Native folder: %s", nativeFolder);

    if (abiList != null) {
        for (File abi : abiList) {
            if (abi.isDirectory()) { // ignore files

                File[] libs = abi.listFiles();
                if (libs != null) {
                    for (File lib : libs) {
                        // only consider files that are .so or, if in debug mode, that
                        // are gdbserver executables
                        if (lib.isFile() &&
                                (PATTERN_NATIVELIB_EXT.matcher(lib.getName()).matches() ||
                                PATTERN_BITCODELIB_EXT.matcher(lib.getName()).matches() ||
                                        (mDebugMode &&
                                                SdkConstants.FN_GDBSERVER.equals(
                                                        lib.getName())))) {
                            String path =
                                SdkConstants.FD_APK_NATIVE_LIBS + "/" +
                                abi.getName() + "/" + lib.getName();

                            try {
                                doAddFile(lib, path);
                            } catch (IOException e) {
                                mBuilder.cleanUp();
                                throw new ApkCreationException(e, "Failed to add %s", lib);
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 15
Project: wrdocletbase   File: Util.java   View Source Code Vote up 4 votes
public static void copyResourceFolder(String resourceFolder, String destDir)
		throws IOException {
	final File jarFile = new File(Util.class.getProtectionDomain()
			.getCodeSource().getLocation().getPath());
	if (jarFile.isFile()) { // Run with JAR file
		resourceFolder = StringUtils.strip(resourceFolder, "/");
		final JarFile jar = new JarFile(jarFile);
		// gives ALL entries in jar
		final Enumeration<JarEntry> entries = jar.entries();
		while (entries.hasMoreElements()) {
			JarEntry element = entries.nextElement();
			final String name = element.getName();
			// filter according to the path
			if (name.startsWith(resourceFolder + "/")) {
				String resDestDir = Util.combineFilePath(destDir,
						name.replaceFirst(resourceFolder + "/", ""));
				if (element.isDirectory()) {
					File newDir = new File(resDestDir);
					if (!newDir.exists()) {
						boolean mkdirRes = newDir.mkdirs();
						if (!mkdirRes) {
							logger.error("Failed to create directory "
									+ resDestDir);
						}
					}
				} else {
					InputStream inputStream = null;
					try {
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						if (inputStream == null) {
							logger.error("No resource is found:" + name);
						} else {
							Util.outputFile(inputStream, resDestDir);
						}

						/* compress js files */
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						compressor.compress(inputStream, name, destDir);
					} finally {
						if (inputStream != null) {
							inputStream.close();
						}
					}
				}
			}
		}
		jar.close();
	} else { // Run with IDE
		final URL url = Util.class.getResource(resourceFolder);
		if (url != null) {
			try {
				final File src = new File(url.toURI());
				File dest = new File(destDir);
				FileUtils.copyDirectory(src, dest);
				Util.compressFilesInDir(src, destDir);
			} catch (URISyntaxException ex) {
				logger.error(ex);
			}
		}
	}
}
 
Example 16
Project: BaseClient   File: DefaultResourcePack.java   View Source Code Vote up 4 votes
public InputStream getInputStreamAssets(ResourceLocation location) throws IOException, FileNotFoundException
{
    File file1 = (File)this.mapAssets.get(location.toString());
    return file1 != null && file1.isFile() ? new FileInputStream(file1) : null;
}
 
Example 17
Project: RootPGPExplorer   File: FileUtils.java   View Source Code Vote up 4 votes
public static boolean isFile(File file) {
    return file.isFile();
}
 
Example 18
Project: pandionj   File: JavaSourceParser.java   View Source Code Vote up 4 votes
private static void validateFilePath(String filePath) {
	File f = new File(filePath);
	if(!f.exists()) throw new IllegalArgumentException(filePath + " does not exist");
	if(!f.isFile())	throw new IllegalArgumentException(filePath + " is not a file");
	if(!f.getAbsolutePath().endsWith(".java")) throw new IllegalArgumentException(filePath + " is not a java file (.java)");
}
 
Example 19
Project: openjdk-jdk10   File: Source.java   View Source Code Vote up 3 votes
/**
 * Read all of the source until end of file. Return it as char array
 *
 * @param file source file
 * @return source as content
 * @throws IOException if source could not be read
 */
public static char[] readFully(final File file) throws IOException {
    if (!file.isFile()) {
        throw new IOException(file + " is not a file"); //TODO localize?
    }
    return byteToCharArray(Files.readAllBytes(file.toPath()));
}
 
Example 20
Project: RLibrary   File: FileUtils.java   View Source Code Vote up 2 votes
/**
 * 判断是否是文件
 *
 * @param file 文件
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isFile(File file) {
    return isFileExists(file) && file.isFile();
}