java输入输出流
-
文件基本处理
-
文件操作类File
-
path=new File("D:/demo")目录 file=new File("D:/demo/test.txt")文件
file=new File("D:/demo","test.txt")
是否目录path.isDirectory() 是否文件file.isFile()
创建目录或文件mkdir() createNewFile()
所有文件path.listFiles() filelist[i].getAbsolutePath()路径
文件搜索类FileFilter与FilenameFilter
-
实现接口FileFilter重写方法accept 因不常用...
文件随机读写类RandomAccessFile
-
rafile=new RandomAccessFile("D:/demo/text.txt","rw") 读写方式
rafile.read()读取一个数据字节
byte[] b=rafile.read(new byte[3]) new String(b)读取字节数组
byte[] b2=rafile.read(new byte[3],1,2) new String(b2)读取指定大小字节数组
rafile.readLine()读取一行字符串
rafile.readUTF()读取中文字符
写文件
rafile.write(100)写入一个数据字节
rafile.write(new byte[]{100,120}) 100 字符d的ASCII
rafile.writeBytes()写入一个字符串rafile.writeChars()每个字符按双字节写入
rafile.writeUTF("中国")中文字符
-
输入输出流
-
InputStream输入字节流
-
FileInputStream文件输入字节流
-
fis=new FileInputStream(File file或"D:/demo/ts.txt")
fis.available()剩余字节数
fis.read()读取ASCII值,信息交换代码
ObjectInputStream对象输入字节流
-
ObjectInputStream要FileInputStream配合使用
new ObjectInputStream(fis).readInt()
读取对象readObject() 这个代码没运行正常
ByteArrayInputStream字节数组输入字节流
-
aais=ByteArrayInputStream(new byte[3]{100,101,102})
b=new byte[3]; aais.read(b)将数据从输入字节流读入字节数组中
new String(b)
StringBufferInputStream字符串输入字节流
-
sbis=new StringBufferInputStream("Hello world").available()剩余字节数
(char)sbis.read()将读取的ASCII值转换为对应字符
-
OutputStream输出字节流
-
FileOutputStream文件输出字节流
-
fos=new FileOutputStream("D:\\deo\\text.txt") b=new byte[]{100,101}
fos.write(b)将字节数组写入文件输出字节流,将ASCII值100,101对应字符为de
ObjectOutputStream对象输出字节流
-
同上...先不细看
ByteArrayOutputStream字节数组输出字节流
-
baos=new ByteArrayOutputStream() b=new byte[2]{100,101}
baos.write(b)将字节数组写入到数组输出字节流中
-
Reader输入字符流
-
FileReader文件输入字符流
-
fr=FileReader("D:\\dem\test.txt") fr.ready()因为有些文件可能为网络文件所以要询问
文件是否缓冲到本地,是否可读
b=new byte[2] fr.read(b)从输入
StringReader字符串输入字符流
-
sr=new StringReader("hello") int c=0
while((c=sr.read())>0) 输入字符流读出ASCII值
System.out.println((char)c)
CharArrayReader数组输入字符流
-
buff=new byte[]{100,101} fr=CharArrayReader(buff)
b=new byte[2] fr.read(b)从数组输入字符流把信息读取到字节数组中
-
Writer输出字符流
-
FileWriter文件输出字符流
-
fw=new FileWrite("D:\\demo\\test.txt") buff=new char[]{'a','b'}
fw.write(buff)
StringWriter字符串输出字符流
-
sw=new StringWrite() sw.write("hello") 将字符输出到输出字符流中
CharArrayWriter数组输出字符流
-
caw=new CharArrayWrite() char=new char[]{'a','b'}
caw.write(char) 将字符数组输出到数组输出字符流中 caw.toString()
-
-
-
749

被折叠的 条评论
为什么被折叠?



