导航:首页 > 文件处理 > 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是否存在文件夹相关的资料

热点内容
a3双面打印pdf 浏览:270
被命令文言文 浏览:717
c语言编译器在线菜鸟 浏览:214
安卓如何使用华为手机助手 浏览:701
怎么查看域服务器名称 浏览:775
如何把苹果的视频传到安卓手机 浏览:612
接口服务器怎么使用 浏览:62
苹果怎么实现安卓全面屏手势 浏览:977
拳皇97最强宏命令 浏览:921
linux安装svn查看 浏览:850
内置函数计算绝对值python 浏览:88
千聊免费课程可以重新加密吗 浏览:507
python能代替php吗 浏览:252
phpexcel样式 浏览:265
安卓手机有没有什么软件可以阻止弹广告的 浏览:306
linux局域网搭建服务器 浏览:690
python编译器mac 浏览:293
windows的doc命令 浏览:463
nfc全加密门禁卡 浏览:636
身份信息被加密 浏览:482