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

网站空间怎么弄浙江和海建设集团网站

网站空间怎么弄,浙江和海建设集团网站,药企做网站,专业做国际网站的公司文章目录 Buffered流拷贝二进制文件创建文件写入文本读取文本文件存读Properties文件 Buffered流拷贝二进制文件 package com.hspedu.chapter19.outputStream;import java.io.*;public class BufferedCopy02 {public static void main(String[] args) {String srcFilePath &q…

文章目录

  • Buffered流拷贝二进制文件
  • 创建文件写入文本
  • 读取文本文件
  • 存读Properties文件

Buffered流拷贝二进制文件

package com.hspedu.chapter19.outputStream;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对象,序列化完成...");}//在编写一个方法,反序列化dog@Testpublic 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.yayakq.cn/news/161321/

相关文章:

  • 绿叶网站怎么做荆州网站建设价格
  • 杨和网站设计做任务打字赚钱的网站
  • 设计的网站源代码怎么做自己建设网站流程
  • 进一步网站建设做基金哪个网站好
  • 网站后台发布文章莱芜都市网二手
  • 网站自适应手机代码wordpress 公司建站
  • 泉州网站建设qzdzi建电影网站赚钱挣钱吗
  • 免费可商用的素材网站做电子请帖网站有哪些
  • 潮动九州网站建设网络营销工具及其特点
  • 网站建设策划书提纲有趣的网站官网
  • 网站建设与维护中国出版社小说阅读网站开发源码
  • 做移动端网站软件系统优化大师官方下载
  • 网站开发需要的学历wordpress怎么固定导航栏
  • 成都网站建设网络公司各种资源都有的搜索引擎
  • 网站备案 新闻审批号wordpress的登录页面模板
  • 网站开发实战wordpress降低数据库查询时间
  • 网站模版 百度云网站备案 接入商名称
  • 网站seo入门企业网站制作公司盈利
  • 网站优化搜索网站运营一般做那些分析
  • dw可以做网站吗国家林业建设工程协会网站
  • 重庆大足网站制作公司哪家专业天津塘沽爆炸
  • 做竞猜网站犯法吗中国icp备案网站
  • 怎么做网站策划中国网新山东
  • 常德政务网站阿里云的虚拟主机用什么做网站
  • 什么做网站的公司好高大上网站
  • 潍坊做电商的网站wordpress分享有图片
  • 网站建设咨询哪家性价比高网站建设费用详细表
  • 合理规划网站结构wordpress 小米商城模板
  • 网站开发工具教程免费网站app下载
  • 中小学网站建站模板石家庄抖音推广公司