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



  • 相关阅读:
    解析Javascript事件冒泡机制
    LeetCode——Flatten Binary Tree to Linked List
    流动python
    HDU2586
    Cannot find ActionMappings or ActionFormBeans collection
    reactor设计模式
    简单的Ajax应用实例
    CString——Left、Right、Find、ReverseFind
    MATLAB新手教程
    八大排序算法总结
  • 原文地址:https://www.cnblogs.com/hijackhou/p/8254083.html
Copyright © 2011-2022 走看看