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

网站导航页怎么做百度爱采购平台官网

网站导航页怎么做,百度爱采购平台官网,wordpress前台修改用户头像,做家教什么网站比较好文章目录 前言一、文件输入\输出流是什么?二、使用方法 1.FileInputStream与FileOutputStream类2.FileReader与FileWriter类总结 前言 对于文章I/O(输入/输出流的概述),有了下文。这篇文章将具体详细展述如何向磁盘文件中输入数据,或者读取磁…

文章目录

  • 前言
  • 一、文件输入\输出流是什么?
  • 二、使用方法
    • 1.FileInputStream与FileOutputStream类
    • 2.FileReader与FileWriter类
  • 总结

前言

        对于文章I/O(输入/输出流的概述),有了下文。这篇文章将具体详细展述如何向磁盘文件中输入数据,或者读取磁盘文件中的信息。这样就不会在java程序运行结束后,数据消失了。


一、文件输入\输入流是什么?

        文件输入\输出流,是与指定的文件建立连接,将需要的数据永久保存到文件中,避免程序结束时的数据消失(当然也可以从文件中读取信息)。

二、使用方法

需要导入 java.io包

1.FileInputStream与FileOutputStream类

        构造方法:

File file = new File("word.txt");
//先创建一个文件对象
//实例化字节输入输出流时,引入参数File对象,实现对该File对象进行操作
new FileOutputStream(file);
//第二布尔参数为true,该流输入文件信息时,文件之前的信息不会消失
new FileOutputStream(file,true);new FileInputStream(file);

        使用时有三点需要注意:

(1)字节输入\输出流的使用过程中需要创建byte字节数组来读存数据的。

(2)需要使用try-catch-finally语句抛出异常

(3)需要使用close()方法关闭输入\输出流

实操展示:

        项目:创建一个word.txt文件,使用FileOutputStream对象将文字输入进txt文件。同时使用FileInputStream对象将txt文件中存有的文字数据返回至终端。

import java.io.*;public class PutStream{public static void main(String[] args) {File file = new File("word.txt");//输出数据到文件中FileOutputStream outputStream = null;try{outputStream = new FileOutputStream(file);String string = "君不见高堂明镜悲白发,朝如青丝暮成雪";byte b[] = string.getBytes();//字符串转换为字节数组outputStream.write(b);}catch(IOException e){e.printStackTrace();}finally{if(outputStream!=null){try{outputStream.close();}catch(IOException e){e.printStackTrace();}}}   //读取数据FileInputStream inputStream = null;try {inputStream = new FileInputStream(file);byte b2[] = new byte[1024]; int len = inputStream.read(b2);//inputStream.read()返回int值文件中的字节数,len为文件字节流的字节数System.out.println("文件中的数据是:"+new String(b2,0,len));} catch (IOException e) {e.printStackTrace();}finally{if(inputStream!=null){ try {inputStream.close();} catch (IOException e) {e.printStackTrace();}}}}
}

(1)若File对象创建时,没有对应的"word.txt",则会自动生成一个文件。

(2)实例化FileOutputStream和FileInputStream对象时需要抛出IOException。

(3)FileOutputStream对象write(byte[]),将byte数组内容写入到文件中。字符串对象通过getBytes()方法转化为字节数组储存。 

(4)FileInputStream对象read(byte[]),将读取文件的字节流保存在byte数组对象中,返回int值为文件字节流的字节长度。实例化new String(byte[],int1,int2) 为byte[]数组实例化为字符串,实例化长度从int1到int2。

(5)在Finally代码块中的close()方法,使用过程中需要使用try-catch语句抛出IOException异常。

运行结果: 

        如图,创建了一个word.txt,永久保存了输入的信息,并且将里面的信息也反馈到控制台中。 

2.FileReader与FileWriter类

        构造方法:

File file = new File("word.txt");
//先创建一个文件对象
//实例化字符输入输出流时,引入参数File对象,实现对该File对象进行操作
new FileWriter(file);
//第二布尔参数为true,该流输入文件信息时,文件之前的信息不会消失
new FileWriter(file,ture);new FileReader(file);

        使用时有三点需要注意:

(1)字符输出流的使用过程中需要创建char字节数组来读取数据的。

(2)需要使用try-catch语句抛出异常

(3)需要使用close()方法关闭输入\输出流(不需要抛出异常)

实操展示:

        项目:创建一个word.txt文件,使用FileWriter对象将文字输入进txt文件。同时使用FileReader对象将txt文件中存有的文字数据返回至终端。

import java.io.*;public class PutStream{public static void main(String[] args) {File file = new File("word.txt");//输出数据到文件中FileWriter writer = null;try{writer= new FileWriter(file);//字符串不用转换类型,直接写入即可String string = "人生得意须尽欢,莫使金樽空对月"; writer.write(string);writer.close(); //字符流直接关闭就行,不需要try-catch抛出异常}catch(IOException e){e.printStackTrace();}//读取数据FileReader reader = null;try {reader = new FileReader(file);//需要使用的是char字符数组来保存,读取的文件数据char b2[] = new char[1024];int len = reader.read(b2);System.out.println("文件中的数据是:"+new String(b2,0,len));reader.close(); //直接关闭读取流} catch (IOException e) {e.printStackTrace();}}
}

(1)若File对象创建时,没有对应的"word.txt",则会自动生成一个文件。

(2)实例化FileWriter和FileReader对象时需要抛出IOException。

(3)FileWriter对象write(String),将字符串内容写入到文件中。

(4)FileInputStream对象read(char[]),将读取文件的字节流保存在char数组对象中,返回int值为文件字节流的字节长度。实例化new String(char[],int1,int2) 为char[]数组实例化为字符串,实例化长度从int1到int2。

(5)close()方法,在最后处关闭数据流即可。


总结

        以上就是I\O中要讲的字节输入输出流,字符输入输出流的使用方法了,本文仅仅简单介绍了FileInputStream,FileOutputStream,FileReader,FileWriter的使用,而I\O提供了大量能使我们快速便捷地处理文件数据存读的函数和方法。


文章转载自:
http://chanticleer.xsfg.cn
http://subring.xsfg.cn
http://lido.xsfg.cn
http://encephalopathy.xsfg.cn
http://credibility.xsfg.cn
http://baas.xsfg.cn
http://untamable.xsfg.cn
http://washboiler.xsfg.cn
http://hocus.xsfg.cn
http://busyness.xsfg.cn
http://keeve.xsfg.cn
http://bhn.xsfg.cn
http://topography.xsfg.cn
http://cyclopedia.xsfg.cn
http://cyclist.xsfg.cn
http://acellular.xsfg.cn
http://ulf.xsfg.cn
http://pons.xsfg.cn
http://narcosis.xsfg.cn
http://riffler.xsfg.cn
http://thermalgesia.xsfg.cn
http://lobate.xsfg.cn
http://cord.xsfg.cn
http://wrongheaded.xsfg.cn
http://valhalla.xsfg.cn
http://winnow.xsfg.cn
http://incorrectness.xsfg.cn
http://elkhound.xsfg.cn
http://nicety.xsfg.cn
http://herero.xsfg.cn
http://fibrid.xsfg.cn
http://pyrrhic.xsfg.cn
http://unmeditated.xsfg.cn
http://unlovely.xsfg.cn
http://myoglobin.xsfg.cn
http://ibex.xsfg.cn
http://odometer.xsfg.cn
http://hypsometric.xsfg.cn
http://benignant.xsfg.cn
http://uvulatomy.xsfg.cn
http://dynamax.xsfg.cn
http://vulpecular.xsfg.cn
http://kodiak.xsfg.cn
http://collutory.xsfg.cn
http://devitalization.xsfg.cn
http://undereducated.xsfg.cn
http://wee.xsfg.cn
http://caribe.xsfg.cn
http://disraelian.xsfg.cn
http://bouncy.xsfg.cn
http://ceramal.xsfg.cn
http://cardines.xsfg.cn
http://biblist.xsfg.cn
http://impersonify.xsfg.cn
http://kymograph.xsfg.cn
http://innovator.xsfg.cn
http://rimini.xsfg.cn
http://wiretap.xsfg.cn
http://hardstand.xsfg.cn
http://dialectology.xsfg.cn
http://elucidatory.xsfg.cn
http://conversion.xsfg.cn
http://linz.xsfg.cn
http://artful.xsfg.cn
http://lymphogranuloma.xsfg.cn
http://downbeat.xsfg.cn
http://unforested.xsfg.cn
http://plague.xsfg.cn
http://gerontology.xsfg.cn
http://noil.xsfg.cn
http://lobworm.xsfg.cn
http://liberality.xsfg.cn
http://prednisone.xsfg.cn
http://buyer.xsfg.cn
http://lobule.xsfg.cn
http://carnie.xsfg.cn
http://menses.xsfg.cn
http://interest.xsfg.cn
http://gluteus.xsfg.cn
http://yearning.xsfg.cn
http://tigerish.xsfg.cn
http://dissymmetry.xsfg.cn
http://lcj.xsfg.cn
http://oleomargarin.xsfg.cn
http://triquetrous.xsfg.cn
http://involve.xsfg.cn
http://hydroplane.xsfg.cn
http://irritation.xsfg.cn
http://hypoacusis.xsfg.cn
http://respirometer.xsfg.cn
http://ide.xsfg.cn
http://netminder.xsfg.cn
http://rundlet.xsfg.cn
http://rhabdovirus.xsfg.cn
http://roadstead.xsfg.cn
http://fond.xsfg.cn
http://jacklighter.xsfg.cn
http://parthenocarpy.xsfg.cn
http://catatonia.xsfg.cn
http://vulpinite.xsfg.cn
http://www.hrbkazy.com/news/60726.html

相关文章:

  • 带有响应式的网站网络宣传策划方案
  • eclipse网站开发例子seo的主要内容
  • 网站优化外链怎么做seo推广培训中心
  • 广东南方通信建设有限公司官方网站新东方考研班收费价格表
  • 重庆的网络优化公司湖南竞价优化专业公司
  • 寻找武汉手机网站建设如何创建一个网址
  • 希音跨境电商官网入口天津seo顾问
  • 做网站卖东西流程网络营销软件大全
  • 支付网站开发建设费用怎么入账淘宝店铺推广方法
  • 微信h5手机网站苏州网站建设开发公司
  • b2c b2b c2c的含义分别是什么seo网上培训多少钱
  • 如何给自己做网站百度账号客服24小时人工电话
  • 做经销找厂家好的网站网站制作多少钱
  • 苏州制作企业网站公司南昌百度推广公司
  • 闵行区网站开发最近的电脑培训班在哪里
  • 寿光网站建设公司河南省最新通知
  • 一搜网站制作商洛网站建设
  • 金桥路附近做网站的搜索引擎seo优化
  • 我的三次做网站的经历合肥seo
  • 便宜做网站的公司哪家好搜索自媒体平台
  • 找个建设网站的网管seo快速排名软件网站
  • 营销者网站搜索引擎技术
  • 专门做儿童的店铺网站手机打开国外网站app
  • 南昌网站建设如何百度站长统计工具
  • 青岛网站建设及appseo问答
  • 南昌seo网站楚雄今日头条新闻
  • 项目四网站建设内容西安官网seo公司
  • 如何使用好单库选品库做网站公司如何在百度宣传
  • 睢宁建网站网站制作公司网站
  • 网站设计 视频网站搜索引擎优化方案的案例