Inputstream:获得的是字节流
StringBufferInputStream A specialized InputStream
that reads bytes from a String
in a sequential manner.
FileInputStream, An input stream that reads bytes from a file.
ByteArrayInputStream A specialized InputStream
for reading the contents of a byte array.
BufferedInputStream Wraps an existing InputStream
and buffers the input
BufferedInputStream buf = new BufferedInputStream(new FileInputStream("file.java"));
Reader:获得的是字符流
StringReader A specialized Reader
that reads characters from a String
in a sequential manner.
InputStreamReader, A class for turning a byte stream into a character stream.没有指定从什么形式变过来,只要是inputstream就行
CharArrayReader, A specialized Reader
for reading the contents of a char array.
FileReader A specialized Reader
that reads from a file in the file system.
BufferedReader, Wraps an existing Reader
and buffers the input.
这样就能转化为字符串了
buffer = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));//从字节流转化字符流 while ((line = buffer.readLine()) != null) { sb.append(line); }
BufferedReader buf= newBufferedReader(newFileReader("file.java"));
file的一些函数:
Java.io.File类主要是完成了文件夹管理的命名、查询文件属性和处理目录等到操作它不进行文件夹内容的读取操作。以下描述了File类的主要常用方法。
File():构造函数,一般是依据文件所在的指定位置来创建文件对象。
CanWrite():返回文件是否可写。
CanRead():返回文件是否可读。
CompareTo(File pathname):检查指定文件路径间的顺序。
delet():从文件系统内删除该文件。
DeleteOnExit():程序顺利结束时从系统中删除文件。
Equals(Object obj):检查特定对象的路径名是否相等。
Exists():判断文件夹是否存在。
GetAbsoluteFile():返回文件的完整路径。
GetAbsolutePath():返回文件的完整路径。
GetName():返回文件名称。
GetParent():返回文件父目录路径。
GetPath():返回文件的潜在相对路径。
GetParentFile():返回文件所在文件夹的路径。
HashCode():返回文件哈希码。
IsDirectory():判断该路径指示的是否是文件。
IsFile():判断该路径指示的是否是文件。
LastModified() :返回文件的最后修改时间标志。
Length():返回文件长度。
List():返回文件和目录清单。
Mkdir():生成指定的目录。
RenameTo(File dest):更名文件。
SetReadOnly():将文件设置为可读。
ToString():返回文件状态的字符串。
ToURL():将文件的路径字符串转换成URL File.GetCreationTime 读取创建时间
File.SetCreationTime 设置创建时间
File.GetLastAccessTime 读取最后访问时间
File.SetLastAccessTime 设置最后访问时间
File.GetLastWriteTime 读取最后修改时间
File.SetLastWriteTime 设置最后修改时间
File.GetAttributes 读取文件属性
File.SetAttributes 设置文件属性