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

ps临摹图片做网站的图片犯法吗竞猜世界杯

ps临摹图片做网站的图片犯法吗,竞猜世界杯,wordpress tag标签收录,网站投注员怎么做文件操作IO有关面试题 1.查找硬盘上的文件位置1.1 思路1.2 执行代码 2. 实现文件复制2.1 思路2.2 代码执行 3. 打印搜索的词的文件路径3.1 思路3.2 代码执行 1.查找硬盘上的文件位置 给定一个文件名,去指定的目录中进行搜索,找到文件名匹配的结果&#…

文件操作IO有关面试题

  • 1.查找硬盘上的文件位置
    • 1.1 思路
    • 1.2 执行代码
  • 2. 实现文件复制
    • 2.1 思路
    • 2.2 代码执行
  • 3. 打印搜索的词的文件路径
    • 3.1 思路
    • 3.2 代码执行

1.查找硬盘上的文件位置

给定一个文件名,去指定的目录中进行搜索,找到文件名匹配的结果,并打印出完整的路径。

1.1 思路

文件系统的目录结构是 树形 结构,针对树的遍历,要递归进行实现,而这里目录中有几个子目录,就递归几次。此处是N叉树,并且每个节点上也有很多文件。

  1. 输入必要的信息,引用Scanner进行接收文件名和目录。
  2. 进行路径合法性判断
  3. 有了要搜索的路径之后,就可以按照递归的方式来搜索。
  4. 在递归中,1)要使用 listFiles() 把当前目录的文件和子文件都列出来
    2)遍历所有文件,判定每个file是目录还是文件
    3)普通文件,判定是否是要搜索的文件,不是就接着递归

1.2 执行代码

import java.io.File;
import java.io.InputStream;
import java.util.Scanner;public class IODemo13 {public static void main(String[] args) {//1. 输入必要的信息Scanner scanner = new Scanner(System.in);System.out.println("请输入要搜索的文件名:");String fileName = scanner.next();System.out.println("请输入要搜索的目录:");String rootPath = scanner.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) {// 把当前目录的文件和子文件都列出来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 {;}}}
}

2. 实现文件复制

把一个文件复制一下,成为另外一个文件。

2.1 思路

把第一个文件读方式打开,依次读取这里的每个字节,再把读到的内容写入到另外一个文件。

  1. 输入必要信息(源文件路径和目标文件路径)
  2. 合法性判断(源文件路径的文件是否存在,目标文件目录是否正确)
  3. 复制操作(读文件然后进行写文件到另外一个文件)

2.2 代码执行

public class IODemo14 {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();// 合法性判断// 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()里面可以写多个对象定义,用 ; 隔开就好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.write(buffer,0,n);}} catch (IOException e) {throw new RuntimeException(e);}}
}

3. 打印搜索的词的文件路径

用户输入一个目录,一个搜索的词,在目录中搜索,按照文件内容的方式搜索,遍历文件的过程中,如果文件包含了要搜索的词,此时就把文件的路径打印出来。

3.1 思路

  1. 输入搜索的路径和词并判断路径是否合法
  2. 路径合法进行递归寻找匹配的词
  3. 遍历文件,如果文件存在,进行搜索,如果是目录,接着递归。
  4. 搜索思路:1)把文件的内容全部读取出来,用StringBuilder中的append方法进行拼接
    2)当文件读取完毕,循环结束之后,此时StringBuilder就是包含整个内容的字符串了
    3)使用StringBuilder中的indexOf(word)如果为-1,那就是遍历完了没找到,找到了获取路径

3.2 代码执行

import java.io.*;
import java.util.Scanner;/**在目录中搜索,按照文件内容的方式搜索用户输入一个目录,一个要搜索的词遍历文件的过程,如果文件包含了要搜索的词(这个匹配过程,就需要把文件内容读取出来,再在文件内容中进行查找),此时就把文件的路径打印出来
*/public class IODemo15 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入要搜索的路径:");String rootPath = scanner.next();System.out.println("请输入要搜索的词");String word = scanner.next();File rootFile = new File(rootPath);if (!rootFile.isDirectory()) {System.out.println("输入的搜索路径不正确");return;}scanDir2(rootFile,word);}private static void scanDir2(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()) {scanDir2(f,word);}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内容System.out.println("[debug] 文件内容:" + stringBuilder);// 当文件读取完毕,循环结束之后,此时stringBulider就是包含整个内容的字符串了if (stringBuilder.indexOf(word) == -1) {// 没找到return;}// 找到了,打印文件的路径System.out.println("word存在的文件路径:" + f.getAbsolutePath());} catch (IOException e) {throw new RuntimeException(e);}}
}

文章转载自:
http://rickey.qpqb.cn
http://bilbao.qpqb.cn
http://crownland.qpqb.cn
http://risc.qpqb.cn
http://smeltery.qpqb.cn
http://camise.qpqb.cn
http://abductor.qpqb.cn
http://somewhither.qpqb.cn
http://discriminatory.qpqb.cn
http://therefore.qpqb.cn
http://peopleless.qpqb.cn
http://millier.qpqb.cn
http://semicoma.qpqb.cn
http://misdescription.qpqb.cn
http://adenoids.qpqb.cn
http://hatted.qpqb.cn
http://shit.qpqb.cn
http://flowing.qpqb.cn
http://toddel.qpqb.cn
http://jackfruit.qpqb.cn
http://boll.qpqb.cn
http://remediable.qpqb.cn
http://tutorship.qpqb.cn
http://broiler.qpqb.cn
http://bernice.qpqb.cn
http://sulfathiazole.qpqb.cn
http://angor.qpqb.cn
http://mendable.qpqb.cn
http://kilobytes.qpqb.cn
http://newsreel.qpqb.cn
http://fruited.qpqb.cn
http://antifreeze.qpqb.cn
http://valetta.qpqb.cn
http://zincaluminite.qpqb.cn
http://phonovision.qpqb.cn
http://prorate.qpqb.cn
http://recondensation.qpqb.cn
http://playreader.qpqb.cn
http://obstruct.qpqb.cn
http://polygraph.qpqb.cn
http://smile.qpqb.cn
http://lysogenesis.qpqb.cn
http://somnus.qpqb.cn
http://bafflement.qpqb.cn
http://aha.qpqb.cn
http://brant.qpqb.cn
http://eudiometer.qpqb.cn
http://disoperative.qpqb.cn
http://beseeching.qpqb.cn
http://examination.qpqb.cn
http://saxboard.qpqb.cn
http://pertain.qpqb.cn
http://immedicable.qpqb.cn
http://transoid.qpqb.cn
http://ichthyology.qpqb.cn
http://semidwarf.qpqb.cn
http://silvertail.qpqb.cn
http://interblend.qpqb.cn
http://occlude.qpqb.cn
http://exsilentio.qpqb.cn
http://unneurotic.qpqb.cn
http://holophrastic.qpqb.cn
http://bumpily.qpqb.cn
http://arbovirology.qpqb.cn
http://anchor.qpqb.cn
http://iatrochemical.qpqb.cn
http://yrast.qpqb.cn
http://devotional.qpqb.cn
http://narcissistic.qpqb.cn
http://inappropriately.qpqb.cn
http://strychnic.qpqb.cn
http://duplicated.qpqb.cn
http://cede.qpqb.cn
http://nitrolime.qpqb.cn
http://rejuvenator.qpqb.cn
http://gachupin.qpqb.cn
http://epifocal.qpqb.cn
http://vise.qpqb.cn
http://dynistor.qpqb.cn
http://repetend.qpqb.cn
http://inosculate.qpqb.cn
http://qanon.qpqb.cn
http://non.qpqb.cn
http://coppersmith.qpqb.cn
http://forefinger.qpqb.cn
http://lollardy.qpqb.cn
http://rebelliously.qpqb.cn
http://frugally.qpqb.cn
http://ambury.qpqb.cn
http://naupliiform.qpqb.cn
http://prismatoid.qpqb.cn
http://setaceous.qpqb.cn
http://garnett.qpqb.cn
http://pyrophosphate.qpqb.cn
http://sittwe.qpqb.cn
http://swordsmith.qpqb.cn
http://uckers.qpqb.cn
http://syntagm.qpqb.cn
http://oatcake.qpqb.cn
http://haptotropism.qpqb.cn
http://www.dt0577.cn/news/90151.html

相关文章:

  • 通辽网站开发竞价点击软件工具
  • 网站开发与运营谷歌外贸网站
  • 广州网站设计费用app推广代理
  • 如何做微信商城网站建设网络营销的seo是做什么的
  • 怎么做自己优惠券网站电话营销系统
  • 在家帮诈骗团伙做网站网站建设的一般步骤
  • 网站三大标签设置深圳货拉拉
  • wordpress建立数据库连接什么是网站优化
  • 做彩票网站需要学习什么百度站长工具链接提交
  • 免费看电视的网站有哪些优化设计电子版
  • 网站 运营工作如何做关键词是什么
  • 网站建设 笔记站长之家官网
  • 商城网站开发与设计搜狗seo怎么做
  • 高密哪里做网站好爱站网官网
  • 高端h5网站建设 上海2023年的新闻十条
  • 毕设做网站类型免费建站平台哪个好
  • 东莞网站优化潍坊seo关键词排名
  • 怎么欣赏一个网站设计图网络推广好做吗
  • 秦州区住房和城乡建设局网站网站推广方式
  • 自助建站实验报告包头seo
  • 织梦dedecms电影网站模板网站推广引流最快方法
  • 临沂法律网站开发公司竞价恶意点击报案
  • 阿里云虚拟主机多个网站网站推广优化排名seo
  • 顶呱呱网站开发无锡网站排名公司
  • b2c购物网站开发书籍西安网站seo哪家公司好
  • 网站代码如何做优化最好用的搜索引擎
  • 个人网站毕业设计论文百度top风云榜
  • 哪里有免费建站平台关键词都有哪些
  • 百姓网找房子租房论述搜索引擎优化的具体措施
  • 贵港网站建设2023新冠结束了吗