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

网站建设与维护就业怎么样域名批量查询工具

网站建设与维护就业怎么样,域名批量查询工具,wordpress调用头像,陕西 网站建设文章目录File文件操作IO流处理流缓冲流转换流对象流File文件操作 利用File类来操作。 文件操作中常用到相对目录和绝对路径 package org.File; import java.io.File; public class demo01 { public static void main(String[] args) { try{ File file new File("…

文章目录

  • File文件操作
  • IO流
  • 处理流
    • 缓冲流
    • 转换流
    • 对象流

File文件操作

利用File类来操作。

文件操作中常用到相对目录和绝对路径

package org.File;  import java.io.File;  public class demo01 {  public static void main(String[] args) {  try{  File file = new File("./test.txt");  
//            文件路径是以项目目录为起点的。  
//            创建一个文件。  file.createNewFile();  }catch (Exception e ) {  e.printStackTrace();  }  }  
}

获取文件名

package org.File;  import java.io.File;  public class demo02 {  public static void main(String[] args) {  try {  File file = new File("src/main/java/org/File/Files/test.txt");  file.createNewFile();  
//            不能创建文件夹,创建的是文件  
//            System.out.println(file.getParentFile());//得到上一层文件夹的对象  
//            System.out.println(file.getParent());//得到上一层文件夹  
//            System.out.println(file.exists());//判断文件是否存在  file.mkdir();file.mkdirs();  
//            创建文件夹,一般选择mkdirs()  }catch (Exception e ){  e.printStackTrace();  }  }  
}

文件的所有相关操作

package org.File;  import java.io.File;  public class demo02 {  public static void main(String[] args) {  try {  File file = new File("src/main/java/org/File/Files/test.txt");  file.createNewFile();  
//            不能创建文件夹,创建的是文件  
//            System.out.println(file.getParentFile());//得到上一层文件夹的对象  
//            System.out.println(file.getParent());//得到上一层文件夹  
//            System.out.println(file.exists());//判断文件是否存在  file.mkdir();file.mkdirs();  
//            创建文件夹,一般选择mkdirs()  //            重命名  file.renameTo(new File("src/main/java/org/File/Files/test2.md"));  
//            删除文件  file.delete();  System.out.println(file.isAbsolute());  
//            判断是否是绝对路劲  
//            判断是不是文件夹  System.out.println(file.isDirectory());  System.out.println(file.isFile());  
//            判断是不是文件  System.out.println(file.length());  
//            查看文件大小  System.out.println(file.getName());  
//            文件名字。  }catch (Exception e ){  e.printStackTrace();  }  }  
}

创建文件的完整步骤

package org.File;  import java.io.File;  
import java.io.IOException;  
import java.text.FieldPosition;  public class demo03 {  public static void main(String[] args) {  File file = new File("resource/test.txt");  
//        1、判断上层文件夹是否存在  File parentFile = file.getParentFile();  if (!parentFile.exists())  {  parentFile.mkdirs();  }  
//        2、创建文件  try {  file.createNewFile();  } catch (IOException e) {  throw new RuntimeException(e);  }  }  
}

IO流

流的分类:

  • 按照读写的方向讲,是输入流和输出流
  • 按照读写单位分,字节流和字符流
  • 流的功能不同分,节点流和处理流

流的家族体系

输入输出
字节流InputStreamOutputStream
字符流ReaderWriter

在这里插入图片描述

节点流和处理流
节点流:直接连接在文件上的
处理流:套在其他流上的

文件流:
FileInputStream
FileOutputStream
FileReader
FileWriter

package org.FileStream;  import com.sun.org.apache.xpath.internal.operations.String;  import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  public class demo01 {  public static void main(String[] args) throws Exception {  //    创建流  FileInputStream fils = new FileInputStream(new File("./src/main/resources/a.txt"));  int read = fils.read();  System.out.println(read);  
//        输出115 s的Ascii码  System.out.println((char) read);  byte[] bs = new byte[1024];  int len = fils.read(bs );  //返回多少个字节  System.out.println(new String());  }  }

读取文件的一套写法

package org.FileStream;  import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  public class demo02 {  public static void main(String[] args) throws Exception {  FileInputStream files = new FileInputStream(new File("./src/main/resources/a.txt"));  byte[] bytes = new byte[1024];  int len=0;  while ((len= files.read(bytes))!=-1){  String s = new String(bytes, 0, len);  System.out.println(s);  }  
//        关闭文件流  files.close();  }  
}

写入文件:

public FileOutputStream(File file, boolean append)

append为true时是在文件后加入数据
默认是false,会清空文件,再添加数据。

package org.FileStream;  import com.sun.org.apache.xpath.internal.operations.String;  import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.FileReader;  public class demo04 {  public static void main(String[] args) throws Exception {  FileReader files = new FileReader(new File("./src/main/resources/a.txt"));  char[] cs = new char[1024];  int len = 0 ;  while ((len = files.read(cs))!=-1){  System.out.println(new String(cs,0 ,len));  }  files.close();  }  
}
package org.FileStream;  import java.io.File;  
import java.io.FileWriter;  
import java.io.IOException;  public class demo05 {  public static void main(String[] args) throws IOException {  FileWriter files = new FileWriter(new File("./src/main/resources/a.txt"),true);  files.write("simple");  files.flush();  files.close();  }  
}

将一张图片从一个地方复制到另一个地方

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d9QbRfYz-1676899099153)(../../images/Pasted%20image%2020230220192957.png)]
就将图片从a移动到b

package org.FileStream;  import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  public class demo06 {  public static void main(String[] args) throws Exception {  File f = new File("a/ba1.jpg");  FileInputStream fis = new FileInputStream(new File("a/ba1.jpg"));  FileOutputStream fos = new FileOutputStream(new File("b/bb1.jpg"));  
//        读取内容  byte[] bs = new byte[1024];  int len =0;  while ((len = fis.read(bs))!=-1){//读取数据  fos.write(bs,0,len);//写数据  }  fis.close();  fos.flush();  fos.close();  //        如果是剪切 ,就把原来的图片删掉就行了  
//        f.delete();  }  
}

在这里插入图片描述

处理流

缓冲流

带有一个缓冲区的数据流
BufferedInputStream
BufferedOutputStream
BufferedReader
BufferedWriter

package org.Process_of_Stream;  import java.io.*;  public class demo01_Buffer_stream {  public static void main(String[] args) throws Exception {  
//        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("/src/main/resources/a.txt")));  
//        这里面套了三层东西,缓冲区套在节点流上,节点流套在文件流上  String path = Thread.currentThread().getContextClassLoader().getResource("a.txt").getPath();  System.out.println(path);  
//        获取路径  BufferedReader br = new BufferedReader(new FileReader(new File(path)));  System.out.println(br.readLine()); //读文本文件最好用的方法  System.out.println(br.readLine());  }  
}

标准的读取文件的写法

package org.Process_of_Stream;  import java.io.*;  public class demo01_Buffer_stream {  public static void main(String[] args) throws Exception {  
//        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("/src/main/resources/a.txt")));  
//        这里面套了三层东西,缓冲区套在节点流上,节点流套在文件流上  String path = Thread.currentThread().getContextClassLoader().getResource("a.txt").getPath();  System.out.println(path);  
//        获取路径  BufferedReader br = new BufferedReader(new FileReader(new File(path)));  //        System.out.println(br.readLine()); //读文本文件最好用的方法  
//        System.out.println(br.readLine());  String str ="";  while ((str=br.readLine())!=null ){  System.out.println(str);  }  }  
}

转换流

有时需要将流进行转换. 一般我们得到的会是一个字节流. 这是一般我们需要转换成字符流

java中有的转换:
字节流 --> 字符流
InputStreamReader
OutputStreamWriter

package org.Process_of_Stream;  import jdk.nashorn.internal.runtime.regexp.joni.exception.SyntaxException;  import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.Scanner;  public class demo02_Convert_stream {  public static void main(String[] args) throws Exception {  
//        系统输入是一个字节流  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
//        通过转换流,将字节流转换成了字符流  String s = br.readLine();  System.out.println(s);  }  
}
package org.Process_of_Stream;  import java.io.IOException;  
import java.io.OutputStreamWriter;  
import java.io.Writer;  public class demo03_Conver_stream {  public static void main(String[] args) throws IOException {  Writer writer = new OutputStreamWriter(System.out);  writer.write("hello simplecatlover");  writer.flush();  
//        writer.close();  //这个流不可以关  System.out.println("sgjagjla");  }  
}

对象流

也就是序列化和反序列化接口
两个类:
ObjectInputStream
ObjectOutputStream

类:
一定要implements Serializable

package org.Process_of_Stream.obj;  import java.io.Serializable;  public class Person implements Serializable {  private int id;  private String name;  private int age;  public Person(int id, String name, int age) {  this.id = id;  this.name = name;  this.age = age;  }  public void setId(int id) {  this.id = id;  }  public void setName(String name) {  this.name = name;  }  public void setAge(int age) {  this.age = age;  }  public int getId() {  return id;  }  public String getName() {  return name;  }  public int getAge() {  return age;  }  
}

序列化:

package org.Process_of_Stream.obj;  import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.ObjectOutputStream;  public class test1 {  public static void main(String[] args) throws Exception {  ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("person.dat")));  Person p = new Person(1,"simple",2);  oos.writeObject(p);  oos.flush();  oos.close();  }  
}

反序列化:


package org.Process_of_Stream.obj;  import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.ObjectOutputStream;  public class test1 {  public static void main(String[] args) throws Exception {  ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("person.dat")));  Person p = new Person(1,"simple",2);  oos.writeObject(p);  oos.flush();  oos.close();  }  
}
http://www.hkea.cn/news/776736/

相关文章:

  • p2p网站开发文档免费b站软件下载
  • 有没有做q版头像的网站今天百度数据
  • wordpress页面修改插件seo顾问阿亮
  • 政府门户网站建设标准国际婚恋网站排名
  • 上海青浦网站建设郑州靠谱seo电话
  • 网站建设怎么样seo专家招聘
  • 在网盘上怎么做自己的网站整站优化推广
  • php建设网站实训百度搜索引擎的总结
  • 怎么在360自己做网站重庆seo排名收费
  • 外贸网站建设浩森宇特教育培训报名
  • 网站开发价目表深圳市前十的互联网推广公司
  • php做视频直播网站关键词竞价广告
  • 重庆怎么站seo深圳网络推广团队
  • 自学软件网站开发网络推广怎样做
  • 最新版的wordpress怎么添加特征图优化关键词的作用
  • 深圳做网站google推广网络营销和传统营销的区别和联系
  • 专业做网站的顺德公司网络推广怎么收费
  • php商城网站建设多少钱天津百度seo排名优化
  • 注册网站免费注册insseo关键词优化推广哪家好
  • 深圳房地产网站开发常见的网络营销工具有哪些
  • .net 网站管理系统湖南企业竞价优化首选
  • 南山区住房与建设局官方网站网络赚钱推广
  • wordpress mycred汉化seo引擎搜索入口
  • 在线教育网站用什么做百度搜索的优势
  • 甘肃省住房城乡建设厅网站首页智能建站模板
  • 智能科技网站模板下载地址百度学术论文查重
  • 网站要怎么做才能让360收录推广品牌的策划方案
  • 做网站前景营销课程培训视频
  • 青海做网站广告开户南京seo
  • wordpress写软文赚钱seo快速培训