当前位置: 首页 > news >正文

济宁做网站深圳网站品牌建设

济宁做网站,深圳网站品牌建设,wordpress 主题宽度,打开app登录文章目录 前言1. 案例12. 案例23. 案例3总结 前言 我们学会了文件的基本操作 文件内容读写操作#xff0c;接下来#xff0c;我们实现一些小工具程序#xff0c;来锻炼我们的能力。 关注收藏, 开始学习吧#x1f9d0; 1. 案例1 扫描指定目录#xff0c;并找到名称中包… 文章目录 前言1. 案例12. 案例23. 案例3总结 前言 我们学会了文件的基本操作 文件内容读写操作接下来我们实现一些小工具程序来锻炼我们的能力。 关注收藏, 开始学习吧 1. 案例1 扫描指定目录并找到名称中包含指定字符的所有普通文件不包含目录并且后续询问用户是否要删除该文件 import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner;/* * 扫描指定目录 * 并找到名称中包含指定字符的所有普通文件不包含目录 * 并且后续询问用户是否要删除该文件 * */ public class Demo10 {public static void main(String[] args) throws IOException {Scanner scanner new Scanner(System.in);System.out.println(请输入您要搜索的根目录: );String rootPath scanner.nextLine();File rootDir new File(rootPath);if (!rootDir.isDirectory()) {System.out.println(您输入的文件不存在或者不是目录, 退出程序);return;}System.out.println(请输入您要搜索的关键词: );String word scanner.nextLine();ListFile result new ArrayList();scanDir(rootDir, word, result);System.out.println(搜索完成, 共搜索到 result.size() 个文件, 分别是);for (File file : result) {System.out.println(file.getCanonicalPath() 请问您是否要删除该文件? y/n: );String in scanner.next();if (in.toLowerCase().equals(y)) {file.delete();System.out.println(删除成功!);}}}static void scanDir(File rootDir, String word, ListFile result) {File[] files rootDir.listFiles();if (files null || files.length 0) {return;}for (File file : files) {if (file.isDirectory()) {scanDir(file, word, result);} else {if (file.getName().contains(word)) {result.add(file);}}}} }2. 案例2 进行普通文件的复制 import java.io.*; import java.util.Scanner;/* * 进行普通文件的复制 * */ public class Demo11 {public static void main(String[] args) throws IOException {Scanner scanner new Scanner(System.in);System.out.println(请输入要复制的源文件路径: );String srcPath scanner.nextLine();File srcFile new File(srcPath);if (!srcFile.exists()) {System.out.println(输入文件不存在, 退出程序);return;}if (!srcFile.isFile()) {System.out.println(输入文件不合法, 退出程序);return;}System.out.println(请输入要复制到的目标路径: );String dstPath scanner.nextLine();File dstFile new File(dstPath);if (dstFile.exists()) {if (dstFile.isDirectory()) {System.out.println(该文件已存在, 并且是一个目录文件, 请确定路径是否正确, 退出程序);return;}if (dstFile.isFile()) {System.out.println(该文件已存在, 请问是否进行覆盖? y/n: );String ans scanner.nextLine();if (ans.toLowerCase().equals(n)) {System.out.println(停止复制);return;}}}try (InputStream inputStream new FileInputStream(srcFile);OutputStream outputStream new FileOutputStream(dstFile)) {while (true) {byte[] buf new byte[1024];int len inputStream.read(buf);if (len -1) {break;}outputStream.write(buf, 0, len);}}System.out.println(复制完成);} }3. 案例3 扫描指定目录并找到名称或者内容中包含指定字符的所有普通文件不包含目录该案例启示就是案例1的升级版。 注意我们现在的方案性能较差所以尽量不要在太复杂的目录下或者大文件下实验 import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner;/* * 扫描指定目录 * 并找到名称或者内容中包含指定字符的所有普通文件不包含目录 * */ public class Demo12 {public static void main(String[] args) throws IOException {Scanner scanner new Scanner(System.in);System.out.println(请输入您要搜索的根目录: );String rootPath scanner.nextLine();File rootDir new File(rootPath);if (!rootDir.isDirectory()) {System.out.println(您输入的文件不存在或者不是目录, 退出程序);return;}System.out.println(请输入您要搜索的关键词: );String word scanner.nextLine();ListFile result new ArrayList();scanDir(rootDir, word, result);System.out.println(搜索完成, 共搜索到 result.size() 个文件, 分别是);for (File file : result) {System.out.println(file.getCanonicalPath() 请问您是否要删除该文件? y/n: );String in scanner.next();if (in.toLowerCase().equals(y)) {file.delete();System.out.println(删除成功!);}}}static void scanDir(File rootDir, String word, ListFile result) throws IOException {File[] files rootDir.listFiles();if (files null || files.length 0) {return;}for (File file : files) {if (file.isDirectory()) {scanDir(file, word, result);} else {if (isContentContanis(file, word)) {result.add(file);}}}}static boolean isContentContanis(File file, String word) throws IOException {StringBuffer stringBuffer new StringBuffer();try (InputStream inputStream new FileInputStream(file);Scanner scanner new Scanner(inputStream)) {while (scanner.hasNextLine()) {stringBuffer.append(scanner.nextLine());stringBuffer.append(\r\n);}return stringBuffer.indexOf(word) ! -1;}} }总结 ✨ 想了解更多知识, 请持续关注博主, 本人会不断更新学习记录, 跟随我一起不断学习. ✨ 感谢你们的耐心阅读, 博主本人也是一名学生, 也还有需要很多学习的东西. 写这篇文章是以本人所学内容为基础, 日后也会不断更新自己的学习记录, 我们一起努力进步, 变得优秀, 小小菜鸟, 也能有大大梦想, 关注我, 一起学习. 再次感谢你们的阅读, 你们的鼓励是我创作的最大动力!!!!!
http://www.hkea.cn/news/14265098/

相关文章:

  • wordpress如何做站群公司网站建设要求
  • 做公司网站的多少钱wordpress网站迁移后插件
  • asp.net做毕业设计网站盐城网站建设培训班
  • 苏州中国建设银行招聘信息网站景观网站设计网站
  • 策划 网站全网搜索软件
  • 广州网站建设有哪些网站开发实训意义
  • wordpress急速主题网站后台优化
  • 海外网站推广公司精准软件
  • 怎么做网站界面分析连接器零售在什么网站做
  • 赣州人才网暑假工搜索优化
  • 网站如何做备份集成装修全屋定制
  • 网站seo工作内容人工智能网站建设
  • 建设网站需要设备大连巨人网络推广有限公司
  • 中核工建设集团网站网站建设在360属于什么类目
  • 网站界面设计实训报告html网页模板下载html模板免费
  • 上海专业做网站价格如何建设微信网站
  • 备案期间的网站打开app线上推广是什么工作
  • 学校网站建设需要多少钱中小企业网站该怎么做
  • 手机网站和微信网站的区别wordpress 10万篇文章
  • 贵州城市和城乡建设官方网站哪里有创建网站的
  • 西安网站排名分析app我的页面设计
  • 网页制作制作网站wordpress 附件清理
  • 做陶瓷公司网站建工社官网
  • 烟台开发区建设局网站做家电网是什么网站
  • 模板网站源码烟台网站建设技术托管
  • 网站开发公司安心加盟wordpress登陆ip唯一
  • 门户类网站费用怎样做自己的视频网站
  • 外国网站的浏览器下载整站优化外包服务
  • 做网站服务器配置应该怎么选岳阳建站公司
  • 淘客那些网站怎么做的郑州网站开发公司电话