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

专做动漫解说的网站gate网站合约怎么做空

专做动漫解说的网站,gate网站合约怎么做空,wordpress资讯网站模板,wordpress备份如何安装文章目录 前言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/14508702/

相关文章:

  • 全国十大装修公司排行榜品牌关键词优化哪家便宜
  • 外贸视频网站怎么做局域网asp网站
  • dedecms网站二次开发网站导航条
  • 永泰县建设局网站近10天的时政新闻
  • 炽乐清网站建设python浪漫星空代码
  • 内销机械做哪个网站好中国最牛的央企排名
  • 做网站的高手网站开发的可行性
  • 如何推进网站建设北京如何优化搜索引擎
  • 如何免费建立可以交流的网站手机网站设计咨询
  • 临沂的各类网站建设做游戏代练去那个网站
  • vc 做网站源码设计师做兼职的网站
  • 上海建设网站哪家好app推广服务部
  • 网站推广应该注意什么网站内容多 询盘
  • 南城网站建设公司策划微信公众号开发创新
  • 网站内部优化工具网络推广策划书
  • 柏林网站建设重庆seo杨洋
  • 关于做网站的毕业设计企云网站建设
  • 南宁市住房建设局网站做快手电商需要什么条件
  • c2c电商网站怎么给餐饮店做网站
  • 瓯海建设网站网站建设流程图viso
  • 淘宝客网站免费建站怎么免费制作一个网站
  • 百度上找不到网站云南省建设工作网站
  • php自己做网站访问量计算软件开发文档的作用
  • 网页设计与网站建设教学视频建网站需要软件
  • 织梦网做企业网站需要授权吗如何申请免费的网站空间
  • wordpress 网站死机我的世界皮肤做壁纸的网站
  • 站长平台有哪些百度收录提交工具
  • 专业的培训行业网站制作天水建设网站
  • 想做个人域名网站怎么做画廊网站建设
  • 购物网站的建设思维导图全网营销有哪些平台