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

企业网站的类型河北网上注册公司流程

企业网站的类型,河北网上注册公司流程,wordpress .mo,百度竞价排名危机事件File对象 File对象本质是一个文件或文件夹#xff0c;用于写入和读取文件内容 注意#xff1a;对于相对路径而言#xff0c;在单元测试方法中的File是相对于Module#xff0c;在main中的File是相对于Project 构造器 File(String pathname)File file1 new File(D:…File对象 File对象本质是一个文件或文件夹用于写入和读取文件内容 注意对于相对路径而言在单元测试方法中的File是相对于Module在main中的File是相对于Project 构造器 File(String pathname)File file1 new File(D:\\workspace); // 对应一个文件夹 File file2 new File(D:\\workspace\test.txt); // 对应一个文件File(String parent, String child)File file new File(D:\\workspace, test.txt); // 第一个参数是文件夹第二个参数可以是文件/文件夹File(File parent, String child)File file1 new File(D:\\workspace); File file2 new File(file1, test.txt); // 第一个参数传入一个File对象且这个对象必须是个文件夹常用方法 获取文件信息 getName()获取文件名称gePath()获取相对路径getAbsolutePath()获取文件绝对路径File getAbsoluteFile()获取绝对路径表示的文件getParent()获取上层目录路径length()获取文件所占的字节lastModified()获取文件最后修改的时间毫秒数)exists()判断文件或目录是否存在isDirectory()是否是一个目录isFile()是否是一个文件canRead()是否可读canWrite()是否可写isHidden()是否隐藏 遍历文件内部 String[] list()返回目录中最外层的所有子目录及子文件File[] listFiles()返回目录中最外层的所有子目录及子文件 操作文件 renameTo(File) 重命名文件移动 前提源文件必须存在目标文件必须不存在且目标文件所在文件夹必须存在File file1 new File(hello.txt); // 假设hello.txt存在 File file2 new File(workspace, world.txt); // 假设workspace存在world.txt不存在 Boolean isSuccess file1.renameTo(file2); // 是否移动成功 System.out.println(isSuccess); // 是否成功createNewFile()创建文件若文件存在则返回falseFile file new File(workspace/hello.txt); try {System.out.println(file.createNewFile()); // 不存在返回true文件已存在返回false } catch(IOException e) {e.printStackTrace(); }delete()删除文件或目录若文件/目录不存在返回false 说明 ① 对于目录而言只能删除空目录 ② 删除不走回收站mkdir()创建一个目录如果当前目录的上层目录不存在则创建失败// 前提只有workspace目录存在 File file new File(workspace/test.txt); file.mkdir(); // 创建成功 File file new File(workspace/a/test.txt); // a目录和test.txt不存在 file.mkdir(); // 创建失败mkdirs()创建多级目录如果当前目录的上层目录也不存在一并创建// 前提只有workspace目录存在 File file new File(workspace/a/test.txt); // a目录和test.txt不存在 file.mkdirs(); // 创建成功a目录和test.txt都被创建IO流 按流向划分输入流、输出流按操作数据单位划分字节流、字符流按IO流的角色划分节点流、处理流 IO流的基础类 抽象基类文件流节点流缓冲流处理流转换流处理流数据流处理流对象流处理流InputStream字节流输入流FileInputStreamBufferedInputStreamInputStreamReaderDataInputStreamObjectInputStreamouputStream字节输出流FileOutputStreamBufferedOutputStreamOutputStreamWriterDataOutputStreamObjectOutputStreamReader字符输入流FileReaderBufferedReaderWriter字符输出流FileWriterBufferedWriterPrintStream打印流 说明 ① 字符流一般用于读取txt文件字节流一般用于读取mp3、mp4、jpg等文件 ② 字节流可以用于txt文件的复制但是用于读取txt文件可能会出现乱码如果遇到汉字一个汉字占3个字节可能读不完整 ③ 缓冲流可以提高文件的读写效率相当于在文件和内存中间架了一层8kb的缓存区先从文件中读取到缓存中最后再一并读入到内存中 ④ 输出流中的flush()方法可以手动将数据立即写入到磁盘中 ⑤ 转换流可以将字节流转换为字符流或者将字符流转换为字节流 ⑥ 数据流只可以读写基本数据类型、String类型数据 ⑦ 对象流既可以读写基本数据类型、String类型数据又可以读写引用类型数据 案例1将磁盘中的文本文件读入内存中并打印文件内容使用字符输入流 FileReader File file new File(hello.txt); FileReader fr null; try {fr new FileReader(file);char[] cBuffer new char[5]; // 用于存储批量读出来的字符int len; // 用于存储本次读取出的长度// 开始读入while((len fr.read(cBuffer)) ! -1) {// 遍历本次所有读出的字符for(int i 0; i len; i) {System.out.println(cBuffer[i]);}} } catch(IOException e) {e.printStackTrace(); } finally {// 关闭字符输入流try {if (fr ! null) {fr.close(); }} catch(IOException e) {e.printStackTrace();} }案例2将内存中的文本数据写入到磁盘文件中使用字符输出流FileWriter FileWriter fw null; try {File file new File(world.txt); // 与目标文件做映射fw new FileWriter(file); // 覆盖原有文件内容// fw new FileWriter(file, true); // 在原有文件基础上追加内容// 开始写入fw.write(这是写入的第一行内容...\n);fw.write(这是写入的第二行内容...\n);fw.write(这是写入的第三行内容...\n);System.out.println(写入成功); } catch(IOException e) {e.printStackTrace(); } finally {// 关闭字符输出流 try {if (fw ! null) {fw.close();}} catch(IOException e) {e.printStackTrace();} }案例3复制某个文本文件中的内容到新文件中使用节点流 FileReader fr null; FileWriter fw null; try {File srcFile new File(test.txt); // 映射源文件File destFile new File(test_copy.txt); // 映射目标文件fr new FileReader(srcFile);fw new FileWriter(destFile);char[] cBuffer new char[5]; // 存储每次读取出来的字符int len; // 记录每次读取出的字符长度// 开始读取while((len fr.read(cBuffer)) ! -1) {// 开始写入fw.write(cBuffer, 0, len); // 写入cBuffer中从下标0开始的len长度数据}System.out.println(复制成功); } catch(IOException e) {e.printStackTrace(); } finally {// 关闭输入流、输出流try {if (fr ! null) fr.close();} catch(IOException e) {e.printStackTrace();}try {if (fw ! null) fw.close();} catch(IOException e) {e.printStackTrace();} }案例4复制jpg文件使用字节流 FileInputStream fis null; FileOutputStream fos null; try {File srcFile new File(workspace, screen.jpg);File destFile new File(workspace, screen_copy.jpg);fis new FileInputStream(srcFile);fos new FileOutputStream(destFile);byte[] bBuffer new byte[1024]; // 存储每次读取出来的字节int len; // 记录每次读取出来字节的长度// 开始读取while((len fis.read(bBuffer)) ! -1) {// 开始写入fos.write(bBuffer, 0, len);}System.out.println(复制成功); } catch(IOException e) {e.printStackTrace(); } finally {// 关闭流try {if (fis ! null) fis.close();} catch(IOException e) {e.printStackTrace();}try {if (fos ! null) fos.close();} catch(IOException e) {e.printStackTrace();} }案例5复制jpg文件使用字节缓冲流 说明关闭处理流会自动关闭内层流 BufferedInputStream bis null; BufferedOutputStream bos null; try {File srcFile new File(workspace, screen.jpg);File destFile new File(workspace, screen_copy.jpg);FileInputStream fis new FileInputStream(srcFile);FileOutputStream fos new FileOutputStream(destFile);bis new BufferedInputStream(fis); // 将输入流用处理流包裹bos new BufferedOutputStream(fos); // 将输出流用处理流包裹byte[] bBuffer new byte[1024];int len;// 使用输入的处理流读取while((len bis.read(bBuffer)) ! -1) {// 使用输出的处理流写入bos.write(bBuffer, 0, len);}System.out.println(复制成功); } catch(IOException e) {e.printStackTrace(); } finally {// 关闭处理流try {if (bis ! null) bis.close();} catch(IOException e) {e.printStackTrace();}try {if (bos ! null) bos.close();} catch(IOException e) {e.printStackTrace();} }案例6复制文本文件使用字符缓冲流 说明BufferReader增加了readLine()方法可以一次性读取一行数据但是换行不能读出来 BufferedReader br null; BufferedWriter bw null; try {br new BufferedReader(new FileReader(new File(workspace, hello.txt))); // 包裹字符输入流bw new BufferedWriter(new FileWriter(new File(workspace, hello_copy.txt))); // 包裹字符输出流String data null; // 存储本次读取出的一行数据while((data br.readLine()) ! null) {bw.write(data);bw.newLine(); // 换行}System.out.println(复制成功); } catch(IOException e) {e.printStackTrace(); } finally {try {if (br ! null) br.close();} catch(IOException e) {e.printStackTrace();}try {if (bw ! null) bw.close();} catch(IOException e) {e.printStackTrace();} }案例7将GBK类型的文件转为UTF-8类型的文件使用转换流 InputStreamReader isr null; OutputStreamWriter osw null; try {File srcFile new File(workspace, hello_GBK.txt);File destFile new File(workspace, hello_UTF8.txt);isr new InputStreamReader(new FileInputStream(srcFile), GBK);osw new OutputStreamWriter(new FileOutputStream(destFile), UTF-8);char[] cBuffer new char[5];int len;while((len isr.read(cBuffer)) ! -1) {String s new String(cBuffer, 0, len);osw.write(s);}System.out.println(转换成功); } catch(IOException e) {e.printStackTrace(); } finally {try {if (isr ! null) isr.close();} catch(IOException e) {e.printStackTrace();}try {if (osw! null) osw.close();} catch(IOException e) {e.printStackTrace();} }案例8将Java对象存储在本地文件中并从本地文件中把Java对象读取到内存中使用对象流 对象的序列化机制允许把内存中的Java对象转换成二进制流从而允许把这种二进制流永久的保存在磁盘上或者通过网络将这种二进制流传输到另一个网络节点当其他程序获取到了这种二进制流就可以恢复成原来的Java对象 序列化将Java对象转成二进制流的过程ObjectOutputStream 反序列化将二进制流恢复成Java对象的过程ObjectInputStream 声明Person类和Account类 注意 ① 自定义的类必须实现Serializable接口才能被序列化并且需要声明static final long serialVersionUIDserialVersionUID是用于标识类的如果不声明serialVersionUID则当类改变时serialVersionUID会自动改变 ② 自定义类中的各个属性也必须是可序列化的比如本例中的Account ③ 类中的属性如果加上transient瞬时的或者static属于类跟对象无关修饰则这些属性不会被序列化会以默认值保存到文件中public class Person implements Serializable{private static final long serialVersionUID 1L;private String name;private int age;private Account account;public Person() {}public Person(String name, int age, Account account) {this.name name;this.age age;this.account account;}// ... setter、getter、toString等方法省略 } class Account implements Serializable{private static final long serialVersionUID 2L;private double balance;public Account() {}public Account(double balance) {this.balance balance;}// ... setter、getter、toString等方法省略 }将Java对象存储在本地文件中序列化过程ObjectOutputStream oos null; try {// 创建文件对象和对象流File file new File(object.dat);oos new ObjectOutputStream(new FileOutputStream(file));// 开始序列化写入oos.writeObject(new Person(a, 18, new Account(1000)));oos.writeUTF(这是一段字符串);System.out.println(写入完成); } catch(IOException e) {e.printStackTrace(); } finally {// 关闭对象流try {if (oos ! null) {oos.close();}} catch(IOException e) {e.printStackTrace();} } 从本地文件中把Java对象读取到内存中反序列化过程ObjectInputStream ois null; try {// 创建文件对象和对象流File file new File(object.dat);ois new ObjectInputStream(new FileInputStream(file));// 开始反序列化读入Person p (Person)ois.readObject();System.out.println(p);String s (String)ois.readUTF();System.out.println(s);System.out.println(读取完成); } catch(IOException | ClassNotFoundException e) { e.printStackTrace(); } finally {// 关闭对象流try {if (ois ! null) {ois.close();}} catch(IOException e) {e.printStackTrace();} }标准输入流System.in 案例从键盘输入并转成大写输出 BufferedReader br null; System.out.print(请输入输入exit退出程序); try {// 这里使用BufferedReader可以调用readLine()来读取输入的一整行数据。// 因为System.in是字节数据所以需要使用转换流把字节流转换为字符流br new BufferedReader(new InputStreamReader(System.in));String line;while((line br.readLine()) ! null) {if (line.equalsIgnoreCase(exit)) {break;}System.out.println(line.toUpperCase());System.out.print(请输入输入exit退出程序);} } catch(IOException e) {e.printStackTrace(); } finally {try {if (br ! null) {br.close();}} catch(IOException e) {e.printStackTrace();} }标准输出流System.out 说明System.out默认将内容打印到控制台中 案例修改System.out默认行为使用System.out输出到某个txt文件中 PrintStream ps null; try {ps new PrintStream(new FileOutputStream(new File(test.txt)));ps.println(这是写入的第一行数据);ps.println(这是写入的第二行数据);// 修改System.out的默认输出方式输出到test.txt中System.setOut(ps);System.out.println(这是写入的第三行数据); } catch(FileNotFoundException e) {e.printStackTrace(); } finally {if (ps ! null){ps.close();} }
http://www.hkea.cn/news/14262349/

相关文章:

  • 东莞知名网站推广为离职员工做的网站
  • 网站开发需要数据库技术北京电商网站开发价格
  • 江门网站建设联系电话ps做网站框架搭建
  • 家装设计网站怎么做图片滤镜网站开发
  • 南明区住房和城乡建设局网站上展厅设计概念方案
  • 电子商务网站推广的方式有哪些单页网站cpa虚拟主机
  • 房产信息门户网站建设方案兰州网络推广徽hyhyk1
  • 网站审批号新闻排版设计用什么软件
  • 青岛外贸假发网站建设wordpress用户前台积分
  • 电子商务网站开发实例安康做网站电话
  • 全返网站建设佛山网站优化指导
  • 怎么把百度到自己的网站在线代理软件
  • 建设通官方网站aspx网站如何架设
  • 网站服务器是什么意思设计制作小车教学视频
  • cms管理手机网站做公司网站 烟台
  • 做网站需要啥wordpress主题制作详解
  • 网站建设合同范本网站建设得缺点
  • 有做火币网这种网站的吗引航科技提供网站建设
  • 长春网站优化平台网站建设与栏目设置
  • 格尔木市住房和城乡建设局网站wordpress数据库替换
  • 房产手机网站开发wordpress iis设置方法
  • 开发网站公司价格网站功能板块
  • 创业谷网站建设方案阳江房产网春天尚院
  • 水果套餐网站推推蛙网站诊断
  • 论坛类网站怎么建设access 网站后台
  • 国内网站建设代理wordpress archive
  • 网站做优化的好处php做各种网站类型得模板
  • 可以免费发帖的网站我的世界图片制作器
  • lamp 网站建设论文如何在公司服务器建个内部 网站
  • 免费刷网站百度关键词域名怎么申请