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下干净卸载mysql详解
转自:http://blog.csdn.net/tjcyjd/article/details/52189182 1.使用以下命令查看当前安装mysql情况 rpm -qa|grep -i mysql ...
- 【做题记录】USACO silver * 50(第一篇)
由于我太菜,决定按照AC人数从小到大慢慢做. BZOJ开了权限号真的快了好多诶~ 29/50 1606: [Usaco2008 Dec]Hay For Sale 购买干草 背包dp 1610: [Us ...
- Linux 服务器--Iptables 端口转发
日常Iptables 端口转发 需求:公司是局域网络,通过一个外网ip,进行互联网的访问.公司的云平台服务器在公网中,虚拟化平台中有一台内部服务器,用于公司某部门的使用,上面运行www 服务,ssh端 ...
- URL传参时中文参数乱码的解决方法
URL传参时,中文参数乱码的解决: 今天在工作中遇到了这样的一个问题,在页面之间跳转时,我将中文的参数放入到url中,使用location进行跳转传参,但是发现接收到的参数值是乱码.我的代码是这样写的 ...
- C# 有关控件、自定义类事件中的委托链的获取、移除操作
直接来代码吧,这样干脆直接,也不耽误我午休了.一切尽在源码中. public class ControlEventTool { /// <summary> /// 移除控件的某类事件, 如 ...
- leetcode703
class KthLargest { public: KthLargest(int k, vector<int> nums) { size = k; for(auto num:nums){ ...
- leetcode498
public class Solution { public int[] FindDiagonalOrder(int[,] matrix) { ); ); + col - ; var ary = ne ...
- ubuntu 桥接备忘
apt install birdge-utils 用于桥接网卡的工具,如命令brctl root@ubuntu:/etc/network# vim interfaces auto br0 ...
- pip / conda 导出和安装环境组件 requirements.txt
pip 批量导出包含环境中所有组件的requirements.txt文件 pip freeze > requirements.txt pip 批量安装requirements.txt文件中包含的 ...
- MenuItem属性
[MenuItem属性] The MenuItem attribute allows you to add menu items to the main menu. The MenuItem attr ...