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 ...
随机推荐
- 使用exe4j把java程序生成可执行的.exe文件
exe4j可以很容易把一个jar打成exe. 下载地址:http://dl.dbank.com/c0owlopqf8 1.下载的安装文件,里面包含一个注册码生成的工具 2.安装exe4j以及破解(注 ...
- 013:Rank、视图、触发器、MySQL内建函数
一. Rank 给出不同的用户的分数,然后根据分数计算排名 (gcdb@localhost) 09:34:47 [mytest]> create table t_rank(id int,scor ...
- sublime text安装插件
http://www.sublimetext.com/ 安装Sublime Text 2插件的方法: 1.直接安装 安装Sublime text 2插件很方便,可以直接下载安装包解压缩到Package ...
- angualr 之 $$phase
对于angular, $$phase 是 作为angular 内部状态表示位,用来标示当前是处于哪个阶段. 用有的阶段有 $digest $apply 在使用的是例如你想调用scope.$apply的 ...
- IDA Pro 权威指南学习笔记(十四) - 操纵函数
IDA 无法定位一个函数调用,由于没有直接的方法到达函数,IDA 将无法识别它们 IDA 可能无法正确确定函数的结束部分,需要手动干预,以更正反汇编代码中的错误 如果编译器已经将函数分割到几个地址范围 ...
- 11.solr学习速成之MoreLikeThis
Solr相似匹配 在网页搜索或电商产品搜索结果页面,很多时候会看到一个相似文档.相似产品或找相似的链接.Solr 使用 MoreLikeThisComponent(MLT)和 MoreLikeT ...
- Foglight 5.6.7 控制台jboss报404
Foglight 5.6.7 控制台jboss报404 [终极问题原来就一数据库权限问题!下文是由问题源找到的类似的dell support的相关文章,但却是关于sql server error的,感 ...
- linux条件变量
条件变量用于线程之间的通信,和互斥锁一起使用.条件变量用于及时通知等待的线程条件的变化,使线程不至于错过变化. 考虑下面的情况,有AB两个线程对index这个全局变量进行++,一个线程C用于判断,in ...
- [转] c# 操作Word
来自 风过四季天 的原文 c# 操作Word总结 在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想 到网页的信 ...
- Asp.net 的工作原理
转:http://www.cnblogs.com/linjiancun/archive/2010/09/14/1825662.html 1.1.1 Asp.net 的工作原理 ...