导航:首页 > 文件处理 > Java是否存在文件夹

Java是否存在文件夹

发布时间:2022-08-15 13:57:14

‘壹’ java 判断文件夹下是否有文件夹

		Filef=newFile("d:/aaa");
if(f.isDirectory()){//判断是不是目录
File[]F1=f.listFiles();//获取目录下文件列表
for(Filef2:F1){//循环文件列表
if(f2.isDirectory()){//判断是不是目录
}else{//是文件
}
}
}

‘贰’ java怎么判断文件夹里面是否还有文件夹

File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript");
//如果文件夹不存在则创建
if (!file .exists() && !file .isDirectory())
{
System.out.println("//不存在");
file .mkdir();
} else
{
System.out.println("//目录存在");
}

‘叁’ java判断目录下是否有文件夹

File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript");
//如果文件夹不存在则创建
if (!file .exists() && !file .isDirectory())
{
System.out.println("//不存在");
file .mkdir();
} else
{
System.out.println("//目录存在");
}

‘肆’ java 验证文件夹是否存在

用file.exists()就行吧
import java.io.*;
import java.util.*;
public class TestStream {

public static boolean isexists(String s){
File f = new File(s);
if(f.exists())
return true;
else
return false;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("输入要查询的文件夹路径:");
String str = in.nextLine();

if(isexists(str))
System.out.println("此文件夹存在");
else
System.out.println("此文件夹不存在");
}

}

如:
输入:E:\资料
输出:此文件夹存在

‘伍’ java判断文件是否存在

java判断文件是否存在:

1、判断文件是否存在,不存在创建文件

‘陆’ Java如何判断文件夹是否存在

方法如下:

public static void judeDirExists(File file)

if (file.exists()) if (file.isDirectory())

System.out.println("dir exists"); }

else System.out.println("the same name file exists, can not create dir"); }41

else System.out.println("dir not exists, create it ..."); 、

file.mkdir();

‘柒’ Java判断文件夹是否存在,不存在就创建

用File类中的.exists()方法判断是否存在
mkdirs创建目录
createNewFile()创建文件
多看看API文档

boolean
exists()

测试此抽象路径名表示的文件或目录是否存在。
createNewFile()

当且仅当不存在具有此抽象路径名指定名称的文件时,不可分地创建一个新的空文件。
boolean
mkdirs()

创建此抽象路径名指定的目录,包括所有必需但不存在的父目录。

‘捌’ Java中怎样根据文件的路径去判断该文件夹中是否存在该文件

1.File testFile = new File(testFilePath);
if(!testFile .exists()){
testFile.mkdirs();
System.out.println("测试文件夹不存在");
}

2.File testFile = new File(testFilePath);
if(!testFile .exists()){
testFile.createNewFile();
System.out.println("测试文件不存在");
}
java中File类自带一个检测方法exists可以判断文件或文件夹是否存在,一般与mkdirs方法(该方法相较于mkdir可以创建包括父级路径,推荐使用该方法)或者createNewFile方法合作使用。
1,如果路径不存在,就创建该路径

2,如果文件不存在,就新建该文件

‘玖’ java判断目录是否存在

public static File checkExist(String filepath) throws Exception{
File file=new File(filepath);
if (file.exists()) {//判断文件目录的存在
System.out.println("文件夹存在!");
if(file.isDirectory()){//判断文件的存在性
System.out.println("文件存在!");
}else{
file.createNewFile();//创建文件
System.out.println("文件不存在,创建文件成功!" );
}
}else {
System.out.println("文件夹不存在!");
File file2=new File(file.getParent());
file2.mkdirs();
System.out.println("创建文件夹成功!");
if(file.isDirectory()){
System.out.println("文件存在!");
}else{
file.createNewFile();//创建文件
System.out.println("文件不存在,创建文件成功!" );
}
}
return file;
}

阅读全文

与Java是否存在文件夹相关的资料

热点内容
javachar数组赋值 浏览:101
自动画颈线指标源码 浏览:70
访问共享文件夹错误代码 浏览:502
代号pdf 浏览:17
java编码规范pdf 浏览:144
linuxshellread 浏览:225
st单片机命名 浏览:860
华为路由器弹出提示命令 浏览:884
服务器地址失效 浏览:639
pdf解码 浏览:918
手机号码系统源码 浏览:625
如何选择云服务器系统 浏览:741
探探视频保存在哪个文件夹 浏览:845
crm免费系统源码 浏览:623
三大本pdf 浏览:607
服务器如何远程ftp连接不了 浏览:292
上海死亡程序员 浏览:185
专业app定制开发哪里有 浏览:256
centos给文件权限命令 浏览:305
小娃娃的玩具从哪里买的app 浏览:375