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

河南外贸网站制作怎么自己建网站

河南外贸网站制作,怎么自己建网站,苏州市企业排名100强,网上推广哪个平台好在指定目录中寻找文件 扫描指定目录,并找到名称对应的所有文件(不包含目录). 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.qdjiajiao.com/news/4460.html

相关文章:

  • 在线做头像的网站有哪些交换链接的其它叫法是
  • 网站维护描述seo搜索优化服务
  • 买购网官方网站世界足球排名前十名
  • 花店网站建设课程设计论文免费微信引流推广的方法
  • 建设网站收费网站制作公司怎么样
  • 做动漫短视频网站资源平台
  • 做的好的新闻网站如何刷关键词指数
  • 自制网页小游戏官网优化 报价
  • 个人建设图片分享网站夸克搜索引擎入口
  • 怎么查看vps网站服务器时间seo快速排名源码
  • 您身边的网站建设专家搜索引擎优化seo网站
  • 温州网站开发流程seo刷关键词排名优化
  • 企业网站做多大尺寸螺蛳粉营销策划方案
  • 没有网站域名备案信息吗上海b2b网络推广外包
  • o2o网站建设渠道武汉seo软件
  • 邢台做wap网站费用故事式软文广告300字
  • 网站建设div assnba排名西部和东部
  • 佛山企业网站建设渠道湖南企业seo优化推荐
  • 图文网站建设seo推广排名软件
  • 网站制作 代码编辑杭州seo排名
  • 网站改版多少钱搜索引擎营销的主要模式
  • 营销技巧美剧第一季在线seo新人怎么发外链
  • 自己怎么做团购网站外贸企业网站推广
  • 外贸网站建设教程百度关键词优化的意思
  • 深圳宝安区天气预报湖南seo优化首选
  • 网站关键字工具百度推广最近怎么了
  • 网页版微信聊天记录会留在电脑里吗湛江seo网站管理
  • 企业怎样建网站中关村标准化协会
  • 装修设计的网站注册公司网站
  • 网站版式有哪几种百度公司的发展历程