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

苏州招聘网站开发婚纱网站怎么做seo

苏州招聘网站开发,婚纱网站怎么做seo,绿色大气网站,网站占有率在指定目录中寻找文件 扫描指定目录,并找到名称对应的所有文件(不包含目录). import java.io.File; import java.util.Scanner;public class Project1 {public static void main(String[] args) {//1.输入必要的信息Scanner sc new Scanner(System.in);System.out.println(&…

在指定目录中寻找文件

扫描指定目录,并找到名称对应的所有文件(不包含目录).

import java.io.File;
import java.util.Scanner;public class Project1 {public static void main(String[] args) {//1.输入必要的信息Scanner sc = new Scanner(System.in);System.out.println("请输入要搜索的文件名: ");String fileName = sc.next();System.out.println("请输入要搜索的目录: ");String rootPath = sc.next();File rootFile = new File(rootPath);if(!rootFile.isDirectory()) {System.out.println("输入的答案有误!");return;}// 2.有了要搜索的路径之后,就可以按照递归的方式来搜索// 知道递归的起点, 还需要知道查询的文件名.scanDir(rootFile, fileName);}private static void scanDir(File rootFile, String fileName) {//1.把当前目录中的文件和子目录都列出来File[] files = rootFile.listFiles();if(files == null) {//空的目录,返回即可return;}//2.遍历上述files,判定每一个file是目录还是文件for(File f : files) {System.out.println("当前遍历到: " + f.getAbsolutePath());if(f.isFile()) {//普通文件,判定文件名是否是搜索的文件if(fileName.equals(f.getName())) {System.out.println("找到了符合要求的文件! " + f.getAbsolutePath());}} else if (f.isDirectory()) {//目录文件,就需要进一步的递归scanDir(f, fileName);} else {//这个else暂时不需要;}}}
}

进行普通文件的复制

import java.io.*;
import java.util.Scanner;public class Project2 {public static void main(String[] args) throws IOException {Scanner sc = new Scanner(System.in);System.out.println("请输入要复制的源文件: ");String srcPath = sc.next();System.out.println("请输入要复制的目标文件");String destPath = sc.next();//合法性判定// 1)srcPath对应的文件是否存在File srcFile = new File(srcPath);if(!srcFile.isFile()) {System.out.println("源文件路径有误");return;}//2)destPath不要求对应的文件存在,但是目录得存在.File destFile = new File(destPath);if(!destFile.getParentFile().isDirectory()) {System.out.println("目标路径有误!");return;}//复制操作try(InputStream inputStream = new FileInputStream(srcFile);OutputStream outputStream = new FileOutputStream(destFile)) {while(true) {byte[] buffer = new byte[1024];int n = inputStream.read(buffer);if(n == -1) {//读取完毕break;}//把读到的内容写入到outputStream中outputStream.write(buffer, 0, n);}}}
}

 查找包含指定字符的文件

import java.io.*;
import java.util.Scanner;public class Project3 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入要搜索的路径: ");String rootPath = sc.next();System.out.println("请输入要查询的词: ");String word = sc.next();File rootFile = new File(rootPath);if(!rootFile.isDirectory()) {System.out.println("输入的路径不正确");return;}scanDir(rootFile, word);}private static void scanDir(File rootFile, String word) {File[] files = rootFile.listFiles();if(files == null) {return;}for(File f : files) {System.out.println("当前遍历到: " + f.getAbsolutePath());if(f.isFile()) {//在文件内容中搜索searchInFile(f, word);} else if(f.isDirectory()) {//递归遍历scanDir(f, word);} else {//这个else暂时不需要;}}}private static void searchInFile(File f, String word) {//通过这个方法在文件内部进行搜索//1.把文件内容全部读取出来try(InputStream inputStream = new FileInputStream(f)) {StringBuilder stringBuilder = new StringBuilder();while(true) {byte[] buffer = new byte[1024];int n = inputStream.read(buffer);if(n == -1) {break;}//此处只是读取出文件的一部分.需要把文件的整体内容拼接到一起String s = new String(buffer, 0, n);stringBuilder.append(s);}//当文件整体读取完毕,循环结束之后,此时stringBuilder就是包含文件整个内容的字符串了.if(stringBuilder.indexOf(word) == -1) {//没找到要返回return;}//找到了,打印文件路径System.out.println("找到了! " + word + " 存在于 " + f.getAbsolutePath());} catch(IOException e) {throw new RuntimeException();}}
}

 

http://www.yayakq.cn/news/805972/

相关文章:

  • 中国最厉害的互联网公司怎样做网站优化 知乎
  • 三 加强门户网站等新媒体建设网站集群 建设方案
  • 请人做竞价网站的要求重点网络运营主要做什么
  • 淮安网站定制.net网站开发环境
  • 工具类网站设计百度site app网站添加到网站首页源文件中的代码是哪些?
  • 新余教育网站建设建设部官网网站
  • 旅游网站开发设计如何创建自媒体手机网站
  • 建设网站用什么好烟台seo快速排名
  • 宁波搭建网站公模仿淘宝详情页做网站
  • 网站维护怎么学学院二级网站建设方案模板
  • 做网站傻瓜做网站电话号码
  • 网站开发小组分工不需要备案如何做网站
  • 北京网站排名方案九江县建设规划局网站
  • 如何免费做网站并发布网站建设论团
  • 如何做融资网站网站制作熊猫建站
  • 哪里有网站开发公司被老板抓到用公司产品做自己的网站
  • 绘画做动作的网站黄冈网站官方登录平台
  • 商务网站建设策划书范文火车头采集wordpress发布
  • 农村网站建设的意义淮南网站开发
  • 佛山网站营销网站开发 书
  • 南宁网站排名优化电话办网
  • 个人网站可以做健康付费知识检测网站的seo效果
  • 企业品牌网站建设方案免费网页下载
  • 网站推广全过程做营销型网站 推广的好处
  • 广州网站开发多少钱网站备案在哪个部门
  • 做电商网站需要注册什么公司名称WordPress预览出错
  • 网站建设外包公司怎么样爱网卡
  • ar做网站做网站域名公司
  • 网站宣传流程网页制作源代码模板
  • 网站中加入地图英文网站推广公司