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

优化网站标题网站建设是干什么的

优化网站标题,网站建设是干什么的,网站集群怎么做,淄博电商网站建设一、输入输出流 输入输出 ------- 读写文件 输入 ------- 从文件中获取数据到自己的程序中,接收处理【读】 输出 ------- 将自己程序中处理好的数据保存到文件中【写】 流 ------- 数据移动的轨迹 二、流的分类 按照数据的移动轨迹分为:输入流 输出流…

一、输入输出流

        输入输出 ------- 读写文件

        输入 ------- 从文件中获取数据到自己的程序中,接收处理【读】

        输出 ------- 将自己程序中处理好的数据保存到文件中【写】

        流 ------- 数据移动的轨迹

二、流的分类

        按照数据的移动轨迹分为:输入流   输出流

        按照每一次读写/数据量的大小将流分成:字节流    字符流

        字节流:每一次可读写一个字节的数据量,一个字节就是8位2进制,可处理任何类型的文

                      件【文本、图片、视频........】

        字符流:每一次可读写一个字符的数据量,一个字符就是16位2进制,只能处理文本类型的

                       文件

三、字节流相关类的使用

        字节输出流 --------- OutPutStream ------- 抽象类 ---------- 不能new --------- 需要找子类

        1.FileOutputStream类

        构造方法:

        FileOutputStream (File file) 通过File 对象创建一个不可追加的字节输出流

        FileOutoutStream (File file,boolean append) 通过File 对象创建一个可追加的字节输出流

        FileOutoutStream (String name) 通过字符串创建一个不可追加的字节输出流

        FileOutoutStream (String name,boolean append) 通过字符串创建一个可追加的字节输出流

public class FileOutputStreamDemo1 {public static void main(String[] args)throws Exception {String  path="F:"+File.separator+"test"+File.separator+"student.txt";//字节输出流--OutputStream--抽象类--FileOutputStream//FileOutputStream类的构造方法//FileOutputStream(String name) 通过String对象创建一个不可追加的字节输出流。  //参数String name--表示文件路劲【目标位置】OutputStream  out1=new FileOutputStream(path);FileOutputStream  out11=new FileOutputStream(path);//FileOutputStream(String name, boolean append)通过String对象创建一个是否追加的字节输出流。//参数1String name--表示文件路劲【目标位置】//参数2boolean append--是否允许追加【true-追加,false-不追加】OutputStream  out2=new FileOutputStream(path,true);FileOutputStream  out22=new FileOutputStream(path,true);//推荐使用File  file=new File(path);//FileOutputStream(File file) 通过File对象创建一个不可追加的字节输出流。 //参数File file--表示文件路劲【目标位置】OutputStream  out3=new FileOutputStream(file);FileOutputStream  out33=new FileOutputStream(file);//FileOutputStream(File file, boolean append) 通过File对象创建一个是否追加的字节输出流。//参数1File file--表示文件路劲【目标位置】//参数2boolean append--是否允许追加【true-追加,false-不追加】OutputStream  out4=new FileOutputStream(file,true);FileOutputStream  out44=new FileOutputStream(file,true);}
}

        实例方法:

        void write (byte[ ]  b) 将b.length个字节从字节数组写入此文件输出流

        void write (byte[ ] b,int off , int len) 将 len字节从位于偏移量 off的指定字节数组写入

        void write (int b) 将指定的字节写入此文件输出流

        void close( ) 关闭文件输出流并释放与此相关的任何系统资源

public class TestFileOutputStream {public static void main(String[] args) throws Exception{String filepath = "F:"+         File.separator+"wangxinghomework"+File.separator+"20230902"+File.separator+"test.txt";File file = new File(filepath);FileOutputStream fileOutputStream = new FileOutputStream(file,true);String data = "hello,zhaomin";byte bytearray[] = data.getBytes();fileOutputStream.write(bytearray);fileOutputStream.close();
//fileOutputStream.write(bytearray,5,8);fileOutputStream.write(97);fileOutputStream.close();}
}

       2. 字节输入流 ------ InputStream ------ 抽象类 ------- 不能new ------- 找子类

        FileInputStream 构造方法:

        FileInputStream(File file) 通过File对象创建一个字节输入流

        FileInputStream(String name) 通过String对象创建一个字节输入流

public class TestFileInputStream {public static void main(String[] args) throws Exception{
//        FileInputStream类构造方法:
//        	FileInputStream(File file) 通过File对象创建一个字节输入流
//        	FileInputStream(String name) 通过String对象创建一个字节输入流String filepath = "F:"+ File.separator+"wangxinghomework"+File.separator+"20230902"+File.separator+"test.txt";File file = new File(filepath);FileInputStream fileInputStream = new FileInputStream(file);FileInputStream fileInputStream1 = new FileInputStream(filepath);}
}

       FileInputStream 实例方法:

       int read () 从该输入流读取一个字节的数据  ,返回值:读取到的具体字节数据的int型,如果到达文件末尾返回-1

        int read (byte[ ]  b) 从该输入流读取最多 b.length个字节的数据为字节数组 ,返回值:读取的总字节数, 如果到达文件末尾返回-1

        void    close() 关闭此文件输入流并释放与流相关联的任何系统资源

public class TestFileInputStream {public static void main(String[] args) throws Exception{String filepath = "F:"+ File.separator+"wangxinghomework"+File.separator+"20230902"+File.separator+"test.txt";File file = new File(filepath);FileInputStream fileInputStream = new FileInputStream(file);//读取一个字节read()int value = fileInputStream.read();String str1 = String.valueOf(value);//转成字符串String类型fileInputStream.close();System.out.println(str1+"ok");//	int	read(byte[] b) 从该输入流读取最多 b.length个字节的数据为字节数组//定义一个字节型数组,用来保存读出的数据byte bytearray[] = new byte[(int) file.length()];//定义一个临时保存读取来的数据int temp = 0;//定义一个数组下标int index = 0;while ((temp=fileInputStream.read()) != -1){bytearray[index] = (byte)temp;index++;}String str = new String(bytearray);System.out.println(str);fileInputStream.close();}
}

     3.DataOutputStream

        DataOutputStream 构造方法:

        DataInputStream(InputStream  in) 创建使用指定的底层InputStream的DataInputStream

        DataOutputStream 实例方法:

void    writeBoolean(boolean v)将 boolean写入底层输出流作为1字节值
void    writeByte(int v)将 byte作为1字节值写入底层输出流
void    writeChar(int v)将 char写入底层输出流作为2字节值,高字节优先
void    writeDouble(double v)双参数传递给转换 long使用 doubleToLongBits方法在类 Double,然后写入该 long值基础输出流作为8字节的数量,高字节
void    writeFloat(float v)浮子参数的转换 int使用 floatToIntBits方法在类 Float ,然后写入 该 int值基础输出流作为一个4字节的数量,高字节。 
void    writeInt(int v)将底层输出流写入 int作为四字节,高位字节
void    writeLong(long v)将 long写入底层输出流,为8字节,高字节为首
void    writeShort(int v)将 short写入底层输出流作为两个字节,高字节优先
void    writeUTF(String str)使用 modified UTF-8编码以机器无关的方式将字符串写入基础输出流
void    flush()刷新此数据输出流
void    close()关闭此输出流并释放与此流相关联的任何系统资源
package com.homework.inouttest;import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;public class TestDataOutputStream {public static void main(String[] args) throws Exception{//构造方法//DataOutputStream(OutputStream out) 创建一个新的数据输出流,以将数据写入指定的底层输出流。String filepath = "F:"+ File.separator+"wangxinghomework"+File.separator+"20230902"+File.separator+"test1.txt";File file = new File(filepath);FileOutputStream out = new FileOutputStream(file,true);DataOutputStream dataOutputStream = new DataOutputStream(out);//DataOutputStream类的实例方法//	void	writeBoolean(boolean v) 将 boolean写入底层输出流作为1字节值。dataOutputStream.writeBoolean(true);//	void	writeByte(int v) 将 byte作为1字节值写入底层输出流。dataOutputStream.writeByte(97);//	void	writeChar(int v) 将 char写入底层输出流作为2字节值,高字节优先。dataOutputStream.writeChar('b');//	void	writeDouble(double v) 双参数传递给转换 long使用 doubleToLongBits方法在类 Double ,		然后写入该 long值基础输出流作为8字节的数量,高字节。dataOutputStream.writeDouble(16.2);//	void	writeFloat(float v) 浮子参数的转换 int使用 floatToIntBits方法在类 Float ,然后写入		该 int值基础输出流作为一个4字节的数量,高字节。dataOutputStream.writeFloat(17.2f);//	void	writeInt(int v) 将底层输出流写入 int作为四字节,高位字节。dataOutputStream.writeInt(23);//	void	writeLong(long v) 将 long写入底层输出流,为8字节,高字节为首。//	void	writeShort(int v) 将 short写入底层输出流作为两个字节,高字节优先。//	void	writeUTF(String str) 使用 modified UTF-8编码以机器无关的方式将字符串写入基础输出流dataOutputStream.writeUTF("wo ai ni");//	void	flush() 刷新此数据输出流。dataOutputStream.flush();//	void	close() 关闭此输出流并释放与此流相关联的任何系统资源。dataOutputStream.close();}
}

         4.DataInputStream类

            DataInputStream类构造方法

            DataInputStream(InputStream  in)创建使用指定的底层InputStream的DataInputStream。

            DataInputStream类实例方法

boolean    readBoolean() 
byte    readByte()
char    readChar()
double    readDouble() 
float    readFloat()
int    readInt()
long    readLong()
short    readShort()
String    readUTF()
void    close()
package com.homework.inouttest1;import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;public class TestDataInputStream {public static void main(String[] args) throws Exception{//构造方法//DataInuptStream(InputStream in)String filepath = "F:"+ File.separator+"wangxinghomework"+File.separator+"20230902"+File.separator+"test1.txt";File file = new File(filepath);FileInputStream inputStream = new FileInputStream(file);DataInputStream dataInputStream = new DataInputStream(inputStream);//实例方法//boolean	readBoolean()boolean flag = dataInputStream.readBoolean();//byte	readByte()byte byt = dataInputStream.readByte();//	char	readChar()char cha = dataInputStream.readChar();//	double	readDouble()double dou = dataInputStream.readDouble();//	float	readFloat()float flo = dataInputStream.readFloat();//	int	readInt()int in = dataInputStream.readInt();//	long	readLong()//	short	readShort()//	String	readUTF()String str = dataInputStream.readUTF();//	void	close()dataInputStream.close();System.out.println(flag+","+byt+","+cha+","+dou+","+flo+","+in+","+str);}
}

        优点:可以直接写出基本数据类型的数据和String,且不需要转换成字节数组
        缺点:保存到文件中的数据是乱码

      5.序列化

        将一个java对象转换成2进制流数据过程,因为我们做操作的java对象可能需要在多台计算机之间传递

        如何实现序列化?

        (1).为被序列化的java对象的生成类实现一个序列化接口【Serializable】
            public interface Serializable特殊----该接口中一个方法都没有,类的序列化由实现java.io.Serializable接口的类启用。不实现此接口的类将不会使任何状态序列化或反序列化。
可序列化类的所有子类型都是可序列化的。

        (2).通过java提供ObjectOutputStream类的writeObject(Object obj)

             ObjectOutputStream的构造方法
             ObjectOutputStream(OutputStream out) 创建一个写入指定的OutputStream的ObjectOutputStream。 
             实例方法
              void    writeObject(Object obj) 将指定的对象写入ObjectOutputStream。

        6.反序列化

           将2进制流数据转换成java对象的过程,需要ObjectInputStream类的Object  readObject()方法读取对象

           ObjectInputStream类的构造方法
                    ObjectInputStream(InputStream  in)
            ObjectInputStream类的实例方法
                    Object    readObject() 从ObjectInputStream读取一个对象

package com.homework.inouttest1;import java.io.Serializable;public class Student implements Serializable {//实例方法,测试用public void learn(){System.out.println("Student类的实例方法");}
}
package com.homework.inouttest;import com.homework.inouttest1.Student;import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;//ObjectOutputStream(Object obj)
public class ObjectOutTest {public static void main(String[] args) throws Exception{String filepath = "F:"+ File.separator+"student.txt";File file = new File(filepath);FileOutputStream outputStream = new FileOutputStream(file);ObjectOutputStream out = new ObjectOutputStream(outputStream);Student student = new Student();out.writeObject(student);out.close();outputStream.close();}
}
package com.homework.inouttest1;import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;public class ObjectInputTest {public static void main(String[] args) throws Exception{String filepath =  "F:"+ File.separator+"student.txt";File file = new File(filepath);FileInputStream fileInputStream = new FileInputStream(file);ObjectInputStream in = new ObjectInputStream(fileInputStream);Object objstudent=in.readObject();Student studentst = (Student)objstudent;in.close();fileInputStream.close();studentst.learn();}
}

从D盘复制jpg类型文件到H盘

package com.homework.inouttest;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;public class CopyTest {public static void main(String[] args)throws Exception {//定义D盘路径String filepath = "D:"+ File.separator;//创建文件对象File file = new File(filepath);//获取D盘所有文件名称File myfilelist[] = file.listFiles();for (File d_file:myfilelist) {String filename = d_file.getName();int houzhui = filename.lastIndexOf(".");if (houzhui != -1){String houzhuiname = filename.substring(houzhui);if (houzhuiname.equals(".jpg")) {//拼接文件路径String jpgpath = filepath + filename;FileInputStream fileInputStream = new FileInputStream(jpgpath);//定义H盘路径String newpath = "H:"+filename;File newfile = new File(newpath);FileOutputStream fileOutputStream = new FileOutputStream(newfile);int temp = 0;while ((temp = fileInputStream.read()) != -1) {fileOutputStream.write(temp);}fileInputStream.close();fileOutputStream.close();}}}}
}


文章转载自:
http://dazzle.yrpg.cn
http://computistical.yrpg.cn
http://mildness.yrpg.cn
http://anglia.yrpg.cn
http://motivate.yrpg.cn
http://gaywings.yrpg.cn
http://languor.yrpg.cn
http://cingulotomy.yrpg.cn
http://brotherly.yrpg.cn
http://touareg.yrpg.cn
http://lymphocytic.yrpg.cn
http://chloroacetone.yrpg.cn
http://epeirogentic.yrpg.cn
http://ballet.yrpg.cn
http://pharyngitis.yrpg.cn
http://adjudgment.yrpg.cn
http://volcaniclastic.yrpg.cn
http://chip.yrpg.cn
http://supposedly.yrpg.cn
http://sloven.yrpg.cn
http://supercharge.yrpg.cn
http://petrinism.yrpg.cn
http://inarticulately.yrpg.cn
http://misorder.yrpg.cn
http://transportability.yrpg.cn
http://printery.yrpg.cn
http://witwatersrand.yrpg.cn
http://acrr.yrpg.cn
http://nihilist.yrpg.cn
http://methadon.yrpg.cn
http://chopboat.yrpg.cn
http://abettal.yrpg.cn
http://cyrenaica.yrpg.cn
http://geostrophic.yrpg.cn
http://laulau.yrpg.cn
http://irrepressible.yrpg.cn
http://rifeness.yrpg.cn
http://pinnatiped.yrpg.cn
http://ritenuto.yrpg.cn
http://politicize.yrpg.cn
http://tautog.yrpg.cn
http://chivy.yrpg.cn
http://monomaniacal.yrpg.cn
http://tribesman.yrpg.cn
http://linguistician.yrpg.cn
http://inche.yrpg.cn
http://buskined.yrpg.cn
http://itinerate.yrpg.cn
http://agaric.yrpg.cn
http://conscientization.yrpg.cn
http://southing.yrpg.cn
http://zealand.yrpg.cn
http://foreworn.yrpg.cn
http://dilatory.yrpg.cn
http://mari.yrpg.cn
http://apogean.yrpg.cn
http://grenadier.yrpg.cn
http://dichroism.yrpg.cn
http://soavemente.yrpg.cn
http://regreet.yrpg.cn
http://microphonics.yrpg.cn
http://intransigent.yrpg.cn
http://polymelia.yrpg.cn
http://feelingful.yrpg.cn
http://silkoline.yrpg.cn
http://knarl.yrpg.cn
http://monographic.yrpg.cn
http://echinus.yrpg.cn
http://myofilament.yrpg.cn
http://lieabed.yrpg.cn
http://saceur.yrpg.cn
http://decaffeinate.yrpg.cn
http://eudaimonism.yrpg.cn
http://hydrophily.yrpg.cn
http://interfertile.yrpg.cn
http://astronautical.yrpg.cn
http://ode.yrpg.cn
http://hrvatska.yrpg.cn
http://campaign.yrpg.cn
http://blousy.yrpg.cn
http://unendowed.yrpg.cn
http://toffee.yrpg.cn
http://adrenalectomy.yrpg.cn
http://ecdyses.yrpg.cn
http://compressibility.yrpg.cn
http://zambezi.yrpg.cn
http://paly.yrpg.cn
http://imbricate.yrpg.cn
http://guerrilla.yrpg.cn
http://subderivative.yrpg.cn
http://diapason.yrpg.cn
http://nomen.yrpg.cn
http://ransack.yrpg.cn
http://sempiternity.yrpg.cn
http://enhalo.yrpg.cn
http://circinate.yrpg.cn
http://dustup.yrpg.cn
http://grillroom.yrpg.cn
http://everyhow.yrpg.cn
http://zymosthenic.yrpg.cn
http://www.dt0577.cn/news/126073.html

相关文章:

  • 网站评估内容 优帮云自己怎么制作一个网站
  • 联网站站长统计app官方网站
  • 齐全的网站建设深圳网
  • 建个网站做外贸seo sem什么意思
  • 网站建设改版百度广告联盟平台官网
  • 做网站新科网站建设百度推广话术全流程
  • wordpress it模板郑州百度网站优化排名
  • 北京南站泰安做网站公司
  • 适合用struts2做的网站seo收费
  • 网页游戏网站bilibili广告公司是做什么的
  • 一个空间两个php网站贵阳百度推广电话
  • 做电影网站资源哪里来的西点培训班一般要多少学费
  • 平凉网站开发bt鹦鹉磁力
  • 哪些公司用.cc做网站手机网站seo免费软件
  • wordpress更改到子目录seo发帖网站
  • 免费浏览的不良网站电商培训心得
  • 网站做跳转对排名有影响吗谷歌官网入口
  • 网页制作与网站建设宝典seo优化方法有哪些
  • 池州哪里做网站网站收录软件
  • 网站建设方面的销售经验seo是什么地方
  • 沪浙网站安全又舒适的避孕方法有哪些
  • 做网站包括什么条件百度推广销售
  • 那种投票网站里面怎么做腾讯新闻最新消息
  • 东莞做营销型网站免费推广平台排行榜
  • macbook air网站开发百度一级代理商
  • 门户网站开发流程视频网络违法犯罪举报网站
  • 咖啡网站建设seo推广效果怎么样
  • 做网站和seo哪个好百度竞价推广投放
  • 怎么建设网站阿里云最大免费发布平台
  • 百度做的网站和其他网站的区别搜索引擎优化涉及的内容