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

博客网站源码wordpress 书籍

博客网站源码,wordpress 书籍,wordpress插件文件不存在,有趣的网站网址之家补充一些用到前面没提到的方法 isDirectory()方法,检查一个对象是否是文件夹,是true不是false isFile()方法,检测一个对象是否为文件,是true不是false 文件的读写操作实践 上一篇大致讲了文件读写操作的基本操作,下面是实践时…

补充一些用到前面没提到的方法

isDirectory()方法,检查一个对象是否是文件夹,是true不是false

isFile()方法,检测一个对象是否为文件,是true不是false

文件的读写操作实践

上一篇大致讲了文件读写操作的基本操作,下面是实践时间

查找文件并删除

public class Demo {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入查找的目录:");String rootDir = scanner.next();File rootFile = new File(rootDir);if(!rootFile.isDirectory()){System.out.println("不是目录");}System.out.println("请输入要删除的关键字:");String keyword = scanner.next();scanDir(rootFile,keyword);}
//遍历目录private static void scanDir(File rootFile, String keyword) {File[] files = rootFile.listFiles();//列出当前目录列表if(files == null){return;//目录为空}for (File file:files){//对比,判断是文件还是目录System.out.println("遍历目录文件"+ file.getAbsolutePath());if (file.isFile()){dealFile(file,keyword);//是文件,判断文件名是否包含删除的关键字}else{scanDir(file,keyword);//目录,则继续递归}}}private static void dealFile(File file, String keyword) {if(file.getName().contains(keyword)){//contains会比对传入file与keyword是否有对部分System.out.println("发现文件:"+ file.getAbsolutePath());//绝对路径System.out.println("是否删除:y/n");Scanner x = new Scanner(System.in);String y = x.next();if (y.equalsIgnoreCase("y")){file.delete();System.out.println("删除成功");}else{System.out.println("没有删除");}}}
}

将文件并且复制到其他目录

public class Demo13 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入源文件路径:");String srcPath = scanner.next();System.out.println("请输入目标文件路径:");String destPath = scanner.next();File srcfile = new File(srcPath);if(!srcfile.isFile()){//判断是否为文件System.out.println("不是源文件或不存在");}File destFil = new File(destPath);if(!destFil.getParentFile().isDirectory()){//判断目标文件目录存不存在System.out.println("目标文件目录不存在");return;}//开始复制文件try(InputStream inputStream = new FileInputStream(srcfile) ;OutputStream outputStream = new FileOutputStream(destFil)){//前面讲要关闭文件我却没有用,这里解释一下是因为try()方法自带了关闭文件功能while(true){byte[] buf = new byte[1024];int n = inputStream.read(buf);if(n == -1){break;}outputStream.write(buf, 0 ,n);}System.out.println("复制成功");} catch (IOException e) {throw new RuntimeException();}}
}

 扫描目录,找到名称或者包含指定字符的所有普通文件(不包含目录)

 

public class Demo14 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入要搜索的路径");String rootPath = scanner.next();File rootfile = new File(rootPath);if (!rootfile.isDirectory()){System.out.println("不是路径");return;}System.out.println("输入搜索关键字");String keyword = scanner.next();scanDir(rootfile,keyword);//扫描}private static void scanDir(File rootfile, String keyword) {File[] files = rootfile.listFiles();//获取当前目录下所有的内容if (files ==null){return;}for (File file :  files){if(file.isFile()){//文件deaFile(file,keyword);}else {//目录scanDir(file,keyword);//递归}}}private static void deaFile(File file, String keyword) {if (file.getName().contains(keyword)){System.out.println("文件名包含关键字" + file.getAbsolutePath());return;}StringBuilder stringBuilder = new StringBuilder();try(Reader reader = new FileReader(file)) {//keyword是字符串,使用字符流while(true){char[] chars = new char[1024];int n = reader.read(chars);if (n ==-1){break;}stringBuilder.append(chars,0,n);}}catch(IOException e){throw new RuntimeException(e);}if(stringBuilder.indexOf(keyword)>= 0){//找到匹配项System.out.println("文件内容包含关键字" + file.getAbsolutePath());return;}}


文章转载自:

http://PAuZepCs.dqfsz.cn
http://UJCHlL86.dqfsz.cn
http://3qmX9Ld3.dqfsz.cn
http://vm6BzLiE.dqfsz.cn
http://8K7VNmzI.dqfsz.cn
http://ueRd6hRr.dqfsz.cn
http://bzsFTSFI.dqfsz.cn
http://FiUXrJRb.dqfsz.cn
http://HLFThm8b.dqfsz.cn
http://mjGxDoQR.dqfsz.cn
http://ADj05mNd.dqfsz.cn
http://lHCthAOc.dqfsz.cn
http://ShGIByLA.dqfsz.cn
http://A5c7WHlA.dqfsz.cn
http://g8P5CHPw.dqfsz.cn
http://9VQecZmL.dqfsz.cn
http://jinsb3W3.dqfsz.cn
http://VrHgqjLH.dqfsz.cn
http://49VOaCvG.dqfsz.cn
http://2iiL5lr9.dqfsz.cn
http://xJYtV9TS.dqfsz.cn
http://muEPvq6T.dqfsz.cn
http://Rc8O3s22.dqfsz.cn
http://vSuJW0kH.dqfsz.cn
http://zACTafK4.dqfsz.cn
http://G4JYnCLb.dqfsz.cn
http://nqFBU5gQ.dqfsz.cn
http://yf3NPN5x.dqfsz.cn
http://aI1v6PkL.dqfsz.cn
http://M1Av9hla.dqfsz.cn
http://www.dtcms.com/wzjs/743774.html

相关文章:

  • 网站记录ip 修改电商网站建设教案
  • 做网站 转行wordpress怎么登陆ftp
  • 网站右侧二维码代码html小清新类型网站
  • 长安镇网站建设重庆网站推广大全
  • 网站设计有创意的主题潍坊美丽乡村建设一般发了哪个网站
  • wordpress有多少网站营销自动化系统
  • 农产品网站建设计划书iis默认网站怎么设置
  • 贵州城乡住房建设厅网站网站如何做微信支付宝支付宝支付
  • 怎么优化网站源代码成都百度推广效果
  • 现在学做网站赚钱吗网架加工多少钱一吨
  • 模板网站和定制网站后缀的区别深圳住房和建设局网站办事跟踪
  • 钢管网站模板网站设计公司杭州
  • 潍坊手机网站网站开发需要的技术
  • 女与男爱做电影网站免费下载重庆网站页设计制作
  • 个人搭建网站要多少钱内容营销案例
  • 建设银行深圳天健世纪支行网站合肥工大建设监理有限公司网站
  • 烟台城乡建设局官方信息网站网页设计实训总结三百字
  • 网站建设外包公司招聘软件项目报价
  • 顺的品牌网站设计信息网站设计分析报告
  • 重庆放心seo整站优化做网站如何找广告商
  • 信息课做网站的软件关于网站建设培训
  • 怎么写公司网站的文案台州做企业网站
  • 富阳网站建设怎样德语网站建设注意事项
  • 北京市建设局网站首页网站目标人群
  • 网站横幅广告怎么做福建省建设监理公司网站
  • 凡客网站可以建设会员系统吗刚做网站做多用户还是单用户
  • 成都电商网站高端大气企业网站
  • 自己做的网站可以有多个前端吗华为云虚拟主机
  • 北京营销网站建设公司app十大免费下载排行榜
  • 旅行社网站规划与建设老版本网站开发工具