学习Java随记之IO编程

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

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

 字节流字符流
输入流InputStreamReader
输出流OutPutStreamWriter

 

  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



 

转载于:https://www.cnblogs.com/hijackhou/p/8254083.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值