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

php创建网站推广网站有效的免费方法

php创建网站,推广网站有效的免费方法,公司做网站注意事项,wordpress 公告栏IO流是用来处理设备之间的数据传输的#xff0c;Java对数据的操作都是使用流的方式处理的#xff0c;而且Java将处理流的操作封装成IO流对象了。 一、IO流的分类 流按照操作的数据分为#xff1a;字节流、字符流 流按照流的方向分为#xff1a;输入流、输出流 二、字节流Java对数据的操作都是使用流的方式处理的而且Java将处理流的操作封装成IO流对象了。 一、IO流的分类 流按照操作的数据分为字节流、字符流 流按照流的方向分为输入流、输出流 二、字节流 inputString------此抽象类是表示字节输入流的所有类的超类。 inputStream提供的方法 inputStream是输入流是应用程序读取数据的方式而read方法就是InputStream读取数据的方式 从API中可以看到read方法一共有三种 1int bin.read();   从输入流中读取数据的下一个字节返回0到255范围内的int字节值如果读到流的末尾就返回-1 public static void main(String[] args) throws IOException {InputStream innew FileInputStream(E:\\learnJava\\hello.txt);int by0;while((byin.read())!-1){ //判断是否读到流的末尾System.out.println(by);}in.close(); //使用完记得关闭}   2public int read(byte[] buf)    从输入流中读取一定数量的字节并将其存储在缓冲区数组 buf中将读取的第一个字节存储在元素 buf[0] 中下一个存储在 buf[1] 中依次类推。读取的字节数最多等于 b 的长度。返回的是实际读取的字节个数如果读到流的末尾依旧返回-1 public static void main(String[] args) throws IOException {InputStream innew FileInputStream(E:\\learnJava\\hello.txt); //创建流对象如果文件不存在抛出FileNotFoundException/*int by0;*/byte [] bufnew byte[1024];int len0; //记录读取的字节个数while((lenin.read(buf))!-1){ //判断是否读到流的末尾System.out.println(new String(buf,0,len));}in.close(); //使用完记得关闭} 3public int read(byte[] buf, int start, int len) 将输入流中长度不超过len的数据字节读入数组从数组的start位置开始存储也就是说将读取的第一个字节存储在元素 b[start] 中下一个存储在 b[start1] 中依次类推。读取的字节数最多等于 len。返回值仍然是读取的字节个数如果读到流的末尾则返回-1. public static void main(String[] args) throws IOException {InputStream innew FileInputStream(E:\\learnJava\\hello.txt); //创建流对象如果文件不存在抛出FileNotFoundException/*int by0;*/byte [] bufnew byte[1024];int len0; //记录读取的字节个数while((lenin.read(buf,0,5))!-1){ //判断是否读到流的末尾System.out.println(new String(buf,0,len));}in.close(); //使用完记得关闭} OuputStream-------此抽象类是表示输出字节流的所有类的超类 OutputStream提供的方法 outputstream是输出流提供了应用程序写出数据的方式提供了三种write方法 1public abstract void write(int b) 将指定的字节写入次输出流中即将参数b的低八位写入到输出流b的高24位将被忽略 OutputStream osnew FileOutputStream(E:\\learnJava\\hello.txt);int b100;os.write(b);os.close();   2public void write(byte[] b) 将b.length个字节从指定的byte数组写入此输入流即将数组b中的所有字节一次写入输出流中。 public static void main(String[] args) throws IOException {InputStream innew FileInputStream(E:\\learnJava\\1.txt);OutputStream osnew FileOutputStream(E:\\learnJava\\hello.txt);int b100;byte [] bufnew byte[in.available()];int len0;while((lenin.read(buf))!-1){ //将输入流保存到byte数组中os.write(buf); //将byte数组中的字节写入到输出流}in.close();os.close();} 其实上面的例子也实现了文件的复制功能 3public void write(byte[] b, int off, int len) 将制定byte数组中从第off个字节开始len个字节写入此输出流元素 b[off] 是此操作写入的第一个字节b[offlen-1] 是此操作写入的最后一个字节。 public static void main(String[] args) throws IOException {InputStream innew FileInputStream(E:\\learnJava\\1.txt);OutputStream osnew FileOutputStream(E:\\learnJava\\hello.txt);int b100;byte [] bufnew byte[in.available()];int len0;while((lenin.read(buf,0,5))!-1){ //将输入流保存到byte数组中os.write(buf,0,5); //将byte数组中的字节写入到输出流}in.close();os.close();} 这种方法和上一种方法一样只是限制了读取的字节个数 4public void flush() 方法 刷新此输出流并强制写出所有缓冲的输出字节。也就是输出流字节传给操作系统具体实现写入磁盘的操作有操作系统实现。 5public void close() 关闭此输出流并释放与此流有关的所有系统资源 inputSteam和OutputStream的子类 1FileInputStream和FileOutputStream FileInputStream 从文件系统中的某个文件中获得输入字节。哪些文件可用取决于主机环境。 FileInputStream 用于读取诸如图像数据之类的原始字节流。 FileOutputStream文件输出流是用于将数据写入 File 或 FileDescriptor 的输出流。文件是否可用或能否可以被创建取决于基础平台。FileOutputStream 用于写入诸如图像数据之类的原始字节的流。 其实上面基本都是以FileinputStream和FileOutStream为例此处在贴一个复制图片的例子实现方法都是一样的。 public static void main(String[] args){FileInputStream finnull;FileOutputStream fosnull;byte []bufnew byte[1024];int len0;try {finnew FileInputStream(E:\\learnJava\\io流.jpg);fosnew FileOutputStream(E:\\learnJava\\temp.jpg);while((lenfin.read(buf))!-1){fos.write(buf);}} catch (IOException e) {e.printStackTrace();}finally {try {fin.close();fos.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}} 2BufferedInputStream和BufferedOutputStream FileInputStream和FileOutputStream是不带缓冲区的每次读取写入时都需要我们自己写一个byte数组充当缓冲区而BufferedInputStream和BufferedOutputStream是实现缓冲的输入输出流 BufferedInputStream 在创建 BufferedInputStream 时会创建一个内部缓冲区数组。在读取或跳过流中的字节时可根据需要从包含的输入流再次填充该内部缓冲区一次填充多个字节。 BufferedOutputStream该类实现缓冲的输出流。 public static void main(String[] args){FileInputStream finnull;FileOutputStream fosnull;try {fin new FileInputStream(E:\\learnJava\\风吹麦浪.mp3);fosnew FileOutputStream(E:\\learnJava\\风吹麦浪_副本.mp3);} catch (FileNotFoundException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}BufferedInputStream binnew BufferedInputStream(fin);BufferedOutputStream bosnew BufferedOutputStream(fos);int len0;try {while((lenbin.read())!-1){bos.write(len);}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {try {bin.close();bos.close();fin.close();fos.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}} 3DataInputStream和DataOutputStream DataInputStream数据输入流允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型。应用程序可以使用数据输出流写入稍后由数据输入流读取的数据。 DataOutputStream数据输出流允许应用程序以适当方式将基本 Java 数据类型写入输出流中。然后应用程序可以使用数据输入流将数据读入。 public static void main(String[] args) throws IOException{//规避一下IO异常//输出DataOutputStream dosnew DataOutputStream(new FileOutputStream(E:\\learnJava\\dataOs.txt));dos.writeInt(100);dos.writeLong(10l);dos.writeInt(-100);dos.writeChar(A);dos.writeUTF(中国);//采用UTF-8编码dos.writeChars(中国);//采用utf-16be编码//读取DataInputStream dinnew DataInputStream(new FileInputStream(E:\\learnJava\\dataOs.txt));System.out.println(din.readInt()); //读取存入的第一个int 100System.out.println(din.readLong());//读取long数据System.out.println(din.readInt());System.out.println(din.readChar()); //读取charSystem.out.println(din.readUTF()); //读取UTF} 三、字符流 字符流操作的是文本文件是文本char序列按照某种编码方案unt-8utf-16begbk序列化而成的文件。 Reader-------用于读取字符流的抽象类 Reader提供 的方法 1public int read() -----读取单个字符 返回值是作为整数读取的字符范围在 0 到 65535 之间 (0x00-0xffff)如果已到达流的末尾则返回 -1 public static void main(String[] args) throws IOException{//规避一下IO异常Reader readernew FileReader(E:\\learnJava\\HelloReader.txt);//保证文件存在否则抛出FileNotFoundExceptionint ch0;while((chreader.read())!-1){System.out.println((char)ch);}reader.close();} 2public int read(char[] cbuf) ----将字符读入数组 返回值为读取的字符数如果已到达流的末尾则返回 -1 public static void main(String[] args) throws IOException{//规避一下IO异常Reader readernew FileReader(E:\\learnJava\\HelloReader.txt);//保证文件存在否则抛出FileNotFoundExceptionchar [] bufnew char[1024];int len0;while((lenreader.read(buf))!-1){System.out.println(new String(buf, 0, len));}reader.close();} 3public abstract int read(char[] cbuf, int off, int len) ----将字符读入数组的某一部分 Writer------写入字符流的抽象类 writer提供的方法 public static void main(String[] args) throws IOException{//规避一下IO异常Writer writernew FileWriter(E:\\learnJava\\HelloWriter.txt);writer.write(100); //写入一个字符writer.write(你好Java);//写入一个字符串char [] bufnew char[]{A,B,中,国};writer.write(buf, 0, buf.length); //写入一个字符数组String strnew String(使用Writer);writer.write(str, 2, 6);writer.close(); } reader和writer的子类 1InputStreamReader和OutputStreamWriter------实现字符流和字节流的转换 InputStreamReader 是字节流通向字符流的桥梁每次调用 InputStreamReader 中的一个 read() 方法都会导致从底层输入流读取一个或多个字节。要启用从字节到字符的有效转换可以提前从底层流读取更多的字节使其超过满足当前读取操作所需的字节。 public static void main(String[] args) throws IOException{//规避一下IO异常InputStreamReader isrnew InputStreamReader(new FileInputStream(E:\\learnJava\\绕口令.txt),gbk);//指出文件的编码方式char [] bufnew char[1024];int len0;while((lenisr.read(buf, 0, buf.length))!-1){System.out.println(new String(buf,0,len));}isr.close();} 其他方法 OutputStreamWriter 是字符流通向字节流的桥梁每次调用 write() 方法都会导致在给定字符或字符集上调用编码转换器。在写入底层输出流之前得到的这些字节将在缓冲区中累积。可以指定此缓冲区的大小不过默认的缓冲区对多数用途来说已足够大。注意传递给 write() 方法的字符没有缓冲。 实例文件的复制 public static void main(String[] args) throws IOException{//规避一下IO异常InputStreamReader isrnew InputStreamReader(new FileInputStream(E:\\learnJava\\绕口令.txt),gbk);//指出文件的编码方式/*创建一个FileWriter对象该对象一被初始化就必须要明确被操作的文件. 而且该文件会被创建到指定目录下如果该目录下已有同名的文件将被覆盖。 其实该步就是明确数据要存放的目的地*/ OutputStreamWriter oswnew OutputStreamWriter(new FileOutputStream(E:\\learnJava\\绕口令_副本.txt), gbk);char [] bufnew char[1024];int len0;while((lenisr.read(buf, 0, buf.length))!-1){osw.write(buf, 0, len); // 写入字符数组的某一部分。}isr.close();osw.close();} 其他方法 2FileReader和FileWriter------直接操作文件 public static void main(String[] args) throws IOException{//规避一下IO异常FileReader fReadernew FileReader(E:\\learnJava\\笑话大全.txt);//直接写文件路径或者文件对象FileWriter fWriternew FileWriter(E:\\learnJava\\笑话大全_副本.txt);//输出到文件没有则创建新的有则覆盖没有编码方式(不同编码方式会有乱码)int len0;char [] bufnew char[1024];while((lenfReader.read(buf,0,buf.length))!-1){fWriter.write(buf,0,len);fWriter.flush();}fReader.close();fWriter.close();} 3BufferedReader和BufferedWriter-----字符流的过滤器 BufferedReader从字符输入流中读取文本缓冲各个字符从而实现字符、数组和行的高效读取。 方法public String readLine() 实现读取一个文本行。通过下列字符之一即可认为某行已终止换行 (\n)、回车 (\r) 或回车后直接跟着换行。   BufferedWriter将文本写入字符输出流缓冲各个字符从而提供单个字符、数组和字符串的高效写入。 public static void main(String[] args) throws IOException{//规避一下IO异常//文件的读操作//使用BufferedReader提高读的效率BufferedReader bReadernew BufferedReader(new InputStreamReader(new FileInputStream(E:\\learnJava\\笑话大全.txt),gbk));//文件输出BufferedWriter bWriternew BufferedWriter(new OutputStreamWriter(new FileOutputStream(E:\\learnJava\\笑话大全_副本2.txt),gbk));String line;while((linebReader.readLine())!null){/*System.out.println(line); //一次读一行line并没有实现换行*/ bWriter.write(line); bWriter.newLine();//实现换行bWriter.flush();}bReader.close();bWriter.close();} 其中BufferedWriter可以使用PrintWrite代替会更方便 public static void main(String[] args) throws IOException{//规避一下IO异常//文件的读操作//使用BufferedReader提高读的效率BufferedReader bReadernew BufferedReader(new InputStreamReader(new FileInputStream(E:\\learnJava\\笑话大全.txt),gbk));//文件输出/* BufferedWriter bWriternew BufferedWriter(new OutputStreamWriter(new FileOutputStream(E:\\learnJava\\笑话大全_副本2.txt),gbk));*/PrintWriter pWriternew PrintWriter(E:\\learnJava\\笑话大全_副本3.txt);String line;while((linebReader.readLine())!null){/*System.out.println(line); //一次读一行line并没有实现换行*/ /* bWriter.write(line); bWriter.newLine();//实现换行bWriter.flush();*/pWriter.println(line); //println自带换行pWriter.flush();} bReader.close();/* bWriter.close();*/} 转载于:https://www.cnblogs.com/Actexpler-S/p/7588518.html
http://www.yutouwan.com/news/481827/

相关文章:

  • 网站设计开户ui设计培训平台
  • 张家口住房和城乡建设部网站嘉兴网站优化联系方式
  • 中商华兴建设有限公司网站环球培训机构官网
  • 南京网站建设索q.479185700网站备案接入商
  • 坊子营销型网站建设知识库管理系统解决方案
  • 做简单的网站班级优化大师网页版登录
  • 专做h5的公司网站石景山网站建设公司哪个好
  • 网站工信部超链接怎么做开发商延期交房怎么办
  • 专门做装修的网站宝塔在本地搭建wordpress
  • 杭州市城乡建设网站discuz下载
  • 淘宝网站建设论文软件开发的环节有哪些
  • 深圳网站建设机构企业管理培训课程免费
  • 论坛做视频网站南京app外包
  • 静态网站开发与实施的论文七台河新闻在线直播
  • 来安网站建设宣传片制作公司业务
  • 深圳建设网站公司简介南宁 网站推广
  • 网站平台建设步骤平台搭建心得
  • 网站描述设置我的世界做弊端网站
  • 网站更改备案信息在哪深圳有做网站最近价格?
  • 本地搭建wordpressseo优化广告
  • 用户体验 网站 外国扬州建设信用网站
  • 个人网站做接口可以么查询建筑资质的网站
  • 陕西省西安市建设局网站网络营销方式单一
  • 做网站首页的尺寸网站重复
  • tornado网站开发网页微信版下载
  • 吃什么补肾壮阳最快速郑州网络优化实力乐云seo
  • 企业免费网站模板品牌高端网站制作机构
  • 最新网站制作发帖子最好的几个网站
  • 加强政务公开网站建设江西建设门户网站
  • 公司网站制作税目精准营销策略