输入输出流的判定是以内存为参照的,如果数据是从文件(数据源)向内存流动则为输入流,否则为输出流。
字节流可以读写二进制文件及任意文件,而字符流只能读写文本文件
字节流 | 字符流 | |
输入流 | InputStream | Reader |
输出流 | OutPutStream | Writer |
File file=new File("d:\\**\\**.txt");//其中文件路径也可这样写("d:/**/**.txt")
File文件类的一些常用方法:
- file.mkdir():创建指定路径的文件夹
- file.createNewFile():创建指定路径的文件
- int file.length():获取文件的大小
- file[] file.listFiles():返回一个指定路径下的文件数组
- boolean file.exists():判断文件是否存在
- file.delete()文件删除
- boolean file.isDirectory():可用于判断文件夹是否存在
- String file.getName();顾名思义
- 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类的常用函数或者常用方法:
- char charAt(int index):
- int indexOf(String str)与int lastindexOf(String str)
- String substring(int startpos,int endindex)与String substring(int startpos)
- string trim()
- byte[] getBytes()与char[] toCharArray()
- String replace(oldChar, newChar)
- String replaceAll(regex, replacement)
- String[] split(String regex)
- boolean isEmpty()
- String.valueOf(int i)
- Integer.parseInt(String str)、Float.parseFloat(String str)
- boolean equals(String str)与boolean equalsIgnoreCase(String str)
- int compareTo(String str)与int compareToIgnoreCase(String str)
- boolean startsWith(String str)与boolean endsWith(String str)
- int length