java IO之File基本操作
public static void main(String[] args) {
// TODO Auto-generated method stub
//"G:\\JAVA\\test\\test.txt"
createNewFile();
showSeparator();
useSepartor();
mkNewDir();
showAllNoSub();
showAllWithSub(new File("G:"+File.separator+"JAVA"+File.separator+"test"+File.separator)); } /*
* 1.创建一个新文件
*/
public static void createNewFile() {
File file = new File("G:\\JAVA\\test\\test.txt");
try {
file.createNewFile();
} catch (Exception e) {
e.printStackTrace();
} } /*
* 2.file类的常量separator,patSeparator。文件分割符 //对于不同的系统分隔符孚不一样
*/
public static void showSeparator() {
System.out.println(File.separator); // \
System.out.println(File.pathSeparator); // ;
} /*
* 3.删除文件,用separator让程序更健壮
*/
public static void useSepartor() {
String fileName = "G:" + File.separator + "JAVA" + File.separator
+ "test" + File.separator + "test.txt";
File file = new File(fileName);
if (file.exists())
file.delete();
else
System.out.println("文件不存在"); } /*
* 4.创建一个文件夹
*/
public static void mkNewDir()
{
String filePath= "G:" + File.separator + "JAVA" + File.separator
+ "test" + File.separator + "newDir";
File file=new File(filePath);
if(file.isDirectory())
System.out.println("dir exit");
else
System.out.println(file.mkdir());
} /*
*5. 列出所在目录的所有文件包括隐藏文件(但是不显示子文件)
*/
public static void showAllNoSub()
{
String filePath="G:"+File.separator+"JAVA"+File.separator+"test";
File file=new File(filePath);
String [] all=file.list();
for(String s:all)
{
System.out.println(s);
}
} /*
*6. 用递归算法,列出所在目录的所有文件包括隐藏文件,包括子文件
*/
public static void showAllWithSub(File file)
{
if(file.isFile()) //判断是文件
System.out.println(" File:"+file.getPath());
else if(file.isDirectory()) //判断是文件夹
{
System.out.println("Dir:"+file.getPath());
File [] allfile=file.listFiles();
for(File f : allfile)
{
showAllWithSub(f);
} } }
java IO之File基本操作的更多相关文章
- [Storm] java.io.FileNotFoundException: File '../stormconf.ser' does not exist
This bug will kill supervisors Affects Version/s: 0.9.2-incubating, 0.9.3, 0.9.4 Fix Version/s: 0.10 ...
- 运行基准测试hadoop集群中的问题:org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /benchmarks/TestDFSIO/io_data/test_
在master(即:host2)中执行 hadoop jar hadoop-test-1.1.2.jar DFSCIOTest -write -nrFiles 12 -fileSize 10240 - ...
- Spark启动报错|java.io.FileNotFoundException: File does not exist: hdfs://hadoop101:9000/directory
at org.apache.spark.deploy.history.FsHistoryProvider.<init>(FsHistoryProvider.scala:) at org.a ...
- com.jcraft.jsch.JSchException: java.io.FileNotFoundException: file:\D:\development\ideaProjects\salary-card\target\salary-card-0.0.1-SNAPSHOT.jar!\BOOT-INF\classes!\keystore\login_id_rsa 资源未找到
com.jcraft.jsch.JSchException: java.io.FileNotFoundException: file:\D:\development\ideaProjects\sala ...
- Java—IO流 File类的常用API
File类 1.只用于表示文件(目录)的信息(名称.大小等),不能用于文件内容的访问. package cn.test; import java.io.File; import java.io.IOE ...
- 关于spark入门报错 java.io.FileNotFoundException: File file:/home/dummy/spark_log/file1.txt does not exist
不想看废话的可以直接拉到最底看总结 废话开始: master: master主机存在文件,却报 执行spark-shell语句: ./spark-shell --master spark://ma ...
- java io包File类
1.java io包File类, Java.io.File(File用于管理文件或目录: 所属套件:java.io)1)File对象,你只需在代码层次创建File对象,而不必关心计算机上真正是否存在对 ...
- Sqoop 抽数报错: java.io.FileNotFoundException: File does not exist
Sqoop 抽数报错: java.io.FileNotFoundException: File does not exist 一.错误详情 2019-10-17 20:04:49,080 INFO [ ...
- Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df8019758/__spark_libs__6824092999244734377.zip does not exist java.io.FileNotFoundException: File file:/private/tmp/spark-d4ebd819
spark伪分布式模式 on-yarn出现一下错误 Diagnostics: File file:/private/tmp/spark-d4ebd819-e623-47c3-b008-2a4df801 ...
随机推荐
- Linux下压缩与解压
转自:http://www.mike.org.cn/blog/index.php?load=read&id=218###pp=0 [在解压或压缩的时候,一般还使用-v选项来现实正在处理的文件信 ...
- [置顶]
ubuntu版本很老,apt-get update更新失败时(W: Failed to fetch ...)------如何创建新的sources.list
在说这个解决方案之前,我先说下,目前遇到的问题: 我使用 sudo apt-get update 之后,更新失败.具体原因如下: W: Failed to fetch http://cn.archiv ...
- 5月5日上课笔记-盒子模型【HTML5】
int 默认值为0 Integer 默认值为null String str="weraarezxsa"; 字符实现升序且唯一 & 非短路与 && 短路与 a ...
- python 之 itertools模块
官方:https://yiyibooks.cn/xx/python_352/library/itertools.html 参考: https://blog.csdn.net/neweastsun/ar ...
- NetworkStream.write只能使用一次,后面再使用无效
public delegate void ShowMessageMethod2(TcpClient tc); private void ShowMessage2(TcpClient tc) { Str ...
- asp.net(c#)GridView实现鼠标悬停高亮显示
搜索了一下,发现对于这种基本都使用girdview中的RowDataBound事件完成,下面看看网上提供的简单方法protected void GridView1_RowDataBound(objec ...
- 「小程序JAVA实战」小程序导航组件(26)
转自:https://idig8.com/2018/08/19/xiaochengxujavashizhanxiaochengxudaohangzujian26/ 来说下 ,小程序的导航组件.源码:h ...
- AES 加密填充 PKCS #7
使用算法AES的时候,涉及到数据填充的部分,数据的填充有很多种方案,用的比较多的有pkcs#5,pkcs#7, 下面的都是从网上转来的.结论就是在AES 的使用中,pkcs#5填充和pkcs#7填充没 ...
- C# event 事件学习
C# event 事件学习 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-26 章节: 简单事件编写 模拟 WPF 控件传递 ...
- overflow与underflow
是新近的firefox浏览器中支持overflow, underflow这两个事件,当某一元素的大小超出父元素的显示范围就会触发overflow事件,如果从超出显示再变回不超出的状态则触发underf ...