zoukankan      html  css  js  c++  java
  • 学习Java随记之IO编程

      输入输出流的判定是以内存为参照的,如果数据是从文件(数据源)向内存流动则为输入流,否则为输出流。

      字节流可以读写二进制文件及任意文件,而字符流只能读写文本文件

      字节流 字符流
    输入流 InputStream Reader
    输出流 OutPutStream Writer

      File file=new File("d:\**\**.txt");//其中文件路径也可这样写("d:/**/**.txt")

      File文件类的一些常用方法:

    1. file.mkdir():创建指定路径的文件夹
    2. file.createNewFile():创建指定路径的文件
    3. int file.length():获取文件的大小
    4. file[] file.listFiles():返回一个指定路径下的文件数组
    5. boolean file.exists():判断文件是否存在
    6. file.delete()文件删除
    7. boolean file.isDirectory():可用于判断文件夹是否存在
    8. String file.getName();顾名思义
    9. String file.getAbsolutePath();顾名思义

      读写文件的字节流2个方法:

          FileInputStream.read(byte[] b)

          FileOutPutStream.write(byte[] b)

      读写文件的字符流2个方法:

          FileReader.read(char[] ch)

          FileWriter.write(char[] ch)

      可以读写字符串String的缓存流:

          BufferedReader.readLine();

          BufferedWriter.write(String str)

      String类的常用函数或者常用方法:

    1. char charAt(int index):
    2. int indexOf(String str)与int lastindexOf(String str)
    3. String substring(int startpos,int endindex)与String substring(int startpos)
    4. string trim()
    5. byte[] getBytes()与char[] toCharArray()
    6. String replace(oldChar, newChar)  
    7. String replaceAll(regex, replacement)
    8. String[] split(String regex)
    9. boolean isEmpty()
    10. String.valueOf(int i)
    11. Integer.parseInt(String str)、Float.parseFloat(String str)
    12. boolean equals(String str)与boolean equalsIgnoreCase(String str)
    13. int compareTo(String str)与int compareToIgnoreCase(String str)
    14. boolean startsWith(String str)与boolean endsWith(String str)
    15. int length



  • 相关阅读:
    AngularJS数据建模(转载)
    Entity Framework Code First ---EF Power Tool 和MySql一起使用遇到的问题
    EF开发程序经常用的几个东西
    jQuery插件---轻量级的弹出窗口wBox
    SQL Server 索引维护sql语句
    windows server2008 r2 下启用 sqlserver 2008的远程连接
    windows2012 r2 提高网速方法
    jQuery validation
    Bootstrap Modal 垂直居中
    shell 循环读取文件及字符串转为数组
  • 原文地址:https://www.cnblogs.com/hijackhou/p/8254083.html
Copyright © 2011-2022 走看看