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

做网站的框架遵义市建设厅网站

做网站的框架,遵义市建设厅网站,智能建站系统下载,网站建设 从用户角度开始专栏#xff1a;JavaEE初阶起飞计划 个人主页#xff1a;手握风云 目录 一、Java文件内容写入 1.1. OutputStream 二、字符流读取和写入 2.1. Reader 2.2. Writer 三、示例练习 3.1. 查找文件功能 一、Java文件内容写入 1.1. OutputStream OutputStream同样只是⼀个抽… 专栏JavaEE初阶起飞计划 个人主页手握风云 目录 一、Java文件内容写入 1.1. OutputStream 二、字符流读取和写入 2.1. Reader 2.2. Writer 三、示例练习 3.1. 查找文件功能 一、Java文件内容写入 1.1. OutputStream OutputStream同样只是⼀个抽象类要使用还需要具体的实现类。我们现在还是只关⼼写入文件中所以使用FileOutputStream。int参数类型是写入要给字节的数据byte[]参数类将b这个字符数组中的数据全部写⼊os中。 import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Demo1 {public static void main(String[] args) {try (OutputStream outputStream new FileOutputStream(./test.txt)) {// “你好”的字符编码outputStream.write(0xe4);outputStream.write(0xbd);outputStream.write(0xa0);outputStream.write(0xe5);outputStream.write(0xa5);outputStream.write(0xbd);} catch (IOException e) {e.printStackTrace();}} } 但上面写的代码每次打开文件都会清空原有的内容我们可以在write方法后面加一个参数append就能从文件末尾追加内容。 二、字符流读取和写入 2.1. Reader import java.io.FileReader; import java.io.IOException; import java.io.Reader;public class Demo3 {public static void main(String[] args) {try (Reader reader new FileReader(./test.txt)) {while (true) {int ch reader.read();if (ch -1) {break;}char c (char) ch;System.out.println(c);}} catch (IOException e) {e.printStackTrace();}} } 我们同样也可以使用字符数组来进行读取。 import java.io.FileReader; import java.io.IOException; import java.io.Reader;public class Demo3 {public static void main(String[] args) {try (Reader reader new FileReader(./test.txt)) {while (true) {char[] chars new char[1024];int c reader.read(chars);if (c -1) {break;}for (int i 0; i c; i) {System.out.println(chars[i]);}}} catch (IOException e) {e.printStackTrace();}} } 2.2. Writer import java.io.FileWriter; import java.io.IOException; import java.io.Writer;public class Demo4 {public static void main(String[] args) {try (Writer writer new FileWriter(./test.txt)) {writer.write(你好世界);} catch (IOException e) {e.printStackTrace();}} } 三、示例练习 3.1. 查找文件功能 扫描指定目录并找到名称中包含指定字符的所有普通文件不包含目录并且后续询问⽤户是否要删除该文件。 import java.io.File; import java.util.Scanner;public class Demo5 {public static void main(String[] args) {Scanner in new Scanner(System.in);System.out.println(请输入要搜索的目录);String dir in.nextLine();System.out.println(请输入要查询的文件名);String filename in.nextLine();// 判断目录是否存在File rootFile new File(dir);if (!rootFile.isDirectory()) {System.out.println(目录不存在);return;}// 利用递归进行搜索searchFile(rootFile, filename);}private static void searchFile(File rootFile, String filename) {// 列出rootFile中的内容File[] files rootFile.listFiles();if (files null) {// 空目录return;}// 遍历files数组判断元素类型for (File file : files) {if (file.isDirectory()) {searchFile(file, filename);} else if (file.isFile()) {if (file.getName().contains(filename)) {tryDel(file);}}}}private static void tryDel(File file) {System.out.println(准备删除文件 file.getAbsolutePath());Scanner in new Scanner(System.in);System.out.println(是否确认删除(Y/N));String choice in.nextLine();if (choice.equalsIgnoreCase(Y)) {file.delete();System.out.println(删除成功);} } }
http://www.pierceye.com/news/73091/

相关文章:

  • 购物网站策划案营销方案论文
  • 定期更新网站中国做的电脑系统下载网站
  • 做安全题目是哪个网站wordpress商城主体
  • 网站建设公司基本流程我想建网站
  • 网站怎么做背景nginx wordpress 404.php
  • 做网站准备材料做网站市场价格多少
  • 山东网站设计公司广州网络公关公司
  • 网站建设体会中国建设劳动协会网站
  • 如何做一个简单的网站代练中介网站有得做吗
  • 建个公司网站需要多少钱注册会计师报名条件
  • 怎样用自己的电脑做网站wordpress设置登陆口
  • 房地产培训网站建设wordpress 注册密码
  • 单位门户网站是什么建设电商网站流程
  • 先建网站还是先做网页东坑镇网站建设
  • 李沧网站建设电话网站开发合同官司
  • 可以提供排版的网站app开发需要哪些知识
  • asp网站设计代做空壳网站主体注销
  • 陵水媒体建站哪家好wordpress最大文件
  • 建设工程询价网站有哪些个人网站的搭建
  • 山西众邦建设集团网站ps在线网页版
  • 网站建设定制网站建设公司哪家好专业郑州网站建设
  • 深圳做网站的wordpress调用排序从大到小
  • 百度电脑版登录网站企业管理公司介绍
  • dw做的网站怎么上传图片网站建设diy
  • 建个网站需要多少钱费用下载小程序安装
  • 外贸网站建设推广公司前景如何5g天天奭5g天天运动网站代码
  • 自己做网站好还是购买网站好logo制作在线
  • 建设网站长沙撤销网站备案
  • 江苏城乡住房建设部网站外贸推广系统
  • 大名县建设局网站杭州网站建设公司费用