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

内江建网站南京建设监理协会网站

内江建网站,南京建设监理协会网站,网络设备互联课设建设企业网站,中国兰州文章目录 Buffered流拷贝二进制文件创建文件写入文本读取文本文件存读Properties文件 Buffered流拷贝二进制文件 package com.hspedu.chapter19.outputStream;import java.io.*;public class BufferedCopy02 {public static void main(String[] args) {String srcFilePath import java.io.*;public class BufferedCopy02 {public static void main(String[] args) {String srcFilePath c:\\bh.jpg;String destFilePath c:\\hsp.jpg;BufferedInputStream bis null;BufferedOutputStream bos null;try {bis new BufferedInputStream(new FileInputStream(srcFilePath));bos new BufferedOutputStream(new FileOutputStream(destFilePath));byte[] buff new byte[1024];int readLen 0;while ((readLen bis.read(buff)) ! -1) {bos.write(buff, 0, readLen);}System.out.println(Copied successfully..);} catch (IOException e) {throw new RuntimeException(e);} finally {try {bis.close();bos.close();} catch (IOException e) {throw new RuntimeException(e);}}} } 创建文件写入文本 import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException;public class Homework01 {public static void main(String[] args) throws IOException {String filePath c:\\mydir;File file new File(filePath);if (!file.exists()) {if (file.mkdirs())System.out.println(filePath has been created successfully..);elseSystem.out.println(filePath was fail to be created..);} else {System.out.println(filePath has already existed..);}String destfile filePath \\hello.txt;File file1 new File(destfile);if (!file1.exists()) {if (file1.createNewFile()) {BufferedWriter bufferedWriter new BufferedWriter(new FileWriter(file1));bufferedWriter.write(hello, world~~ 韩顺平教育);bufferedWriter.close();System.out.println(destfile has been created successfully..);} else {System.out.println(destfile has already existed..);}} else {System.out.println(destfile has already existed..);}} } 读取文本文件 public class Homework02 {public static void main(String[] args) throws IOException {String filePath c:\\hello.txt;String line ;int lineNum 0;BufferedReader bufferedReader new BufferedReader(new FileReader(filePath));while ((line bufferedReader.readLine()) ! null) {System.out.println(lineNum line);}if (bufferedReader ! null)bufferedReader.close();} }public class Homework02 {public static void main(String[] args) throws IOException {String filePath c:\\hello.txt;// InputStreamReader指定编码方式InputStreamReader isr new InputStreamReader(new FileInputStream(filePath), gbk);String line ;int lineNum 0;BufferedReader bufferedReader new BufferedReader(isr);while ((line bufferedReader.readLine()) ! null) {System.out.println(lineNum line);}if (bufferedReader ! null)bufferedReader.close();} }存读Properties文件 public class Homework03 {public static void main(String[] args) throws IOException {String filePath src\\dog.properties;Properties properties new Properties();properties.load(new FileReader(filePath));String name properties.get(name) ; //Object - Stringint age Integer.parseInt(properties.get(age) );// Object - intString color properties.get(color) ;//Object - StringDog dog new Dog(name, age, color);System.out.println(dog对象信息);System.out.println(dog);//将创建的Dog 对象 序列化到 文件 dog.dat 文件String serFilePath c:\\dog.dat;ObjectOutputStream oos new ObjectOutputStream(new FileOutputStream(serFilePath));oos.writeObject(dog);//关闭流oos.close();System.out.println(dog对象序列化完成...);}//在编写一个方法反序列化dogTestpublic void m1() throws IOException, ClassNotFoundException {String serFilePath e:\\dog.dat;ObjectInputStream ois new ObjectInputStream(new FileInputStream(serFilePath));Dog dog (Dog)ois.readObject();System.out.println(反序列化后 dog);System.out.println(dog);ois.close();} }class Dog implements Serializable{private String name;private int age;private String color;public Dog(String name, int age, String color) {this.name name;this.age age;this.color color;}Overridepublic String toString() {return Dog{ name name \ , age age , color color \ };} }
http://www.sczhlp.com/news/197821/

相关文章:

  • 和平天津网站建设免费做ppt网站
  • 网站开发文档模板 开源国内网站空间购买
  • 网站建设步骤大全wordpress 简繁
  • 石家庄哪家公司做网站好可以跟关键词密度过高的网站交换友情链接吗
  • 企业网站建设立项请示漯河做网站哪家好
  • 网站制作与建设书籍这几年做啥网站致富
  • 做违法网站犯法吗设计网站外网
  • 杭州高端网站建设公司哪家好搜题在线使用网页版
  • 建设网站的方法怎么做页游网站运营
  • php网站 config手机建筑网
  • 淘客网站cms怎么做网站单个页面
  • 化妆品网站建设的维护毕业设计网站开发的中期报告
  • 小波app推广网网站优化西安
  • 建设官方网站e路护航建设哪里看额度
  • 中国建设银行陕西分行官方网站学校网站制作推荐
  • 摄影网站cnu视觉联盟做音乐网站赚钱吗
  • 房地产网站做百度推广10月哪个网站做电影票活动
  • 档案网站的建设方案北京传媒公司排行榜
  • qq刷赞网站推广wordpress 插件升级慢
  • 在门户网站做产品单页多少钱一天专业宣传片制作拍摄公司
  • 2025 年射线防护服生产厂家最新推荐排行榜:覆盖 X 射线 / 医用 / 中子射线防护服及防护裙、防护屏等品类,为医疗安检领域精选优质品牌
  • 2025 最新阳澄湖大闸蟹权威推荐排行榜,揭秘优质品牌的独特魅力大闸蟹蟹卡 / 大闸蟹礼盒 / 大闸蟹礼券 / 好蟹汇大闸蟹选择指南
  • 碳中和背景下的能源数字化:MyEMS 为企业提供精准碳管理方案
  • 在 VS Code 中集成 LaTeX 环境并创建第一个文档
  • 联合会网站建设在阿里巴巴上做网站需要什么软件
  • 网站开发工具需求网站空间数据库上传
  • 网站建设项目需求分析流程图做h5那个网站好
  • 网站里添加斗鱼直播的视频怎么做铁法能源公司网站
  • 深圳市富通建设工程有限公司网站肥西建设局官方网站
  • 网站电子备案龙岗网站制作效果