JavaI/O编程---File文件操作
File类的基本使用
构造方法:
public File (String pathname)
public File(FIle parent,String child)
创建文件:
public boolean ceratNewFile() throws IOException
删除文件:
public boolean delete()
判断文件是否存在:
public boolean exists()
路径分隔符
File file = new File( "d:"+ File.separator + "mldn.txt")
字节流和字符流
①OutputStream字节输出流
java.io.OutputStream 抽象类
OutputStream out put = new FileOutputStream(file);
String str=" sdsd";
output.write(str.get Bytes())
output.close();
②InputStream字节输入流
InputStream input = new FileInputStream(file);
byte data[] = new byte [1024];
int len = intput.read(data; //read方法返回字节个数
System.out.println (" new String(data,o,len)") ;
input.close();
读取全部字节数据的方法:
byte data[]= input.readAllBytes( ) ;
Writer 字符输出流 (直接支持字符串输出)
Writer 类常用方法:
public writer append (CharSequence scq) throws IOException 追加输出内容
Reader字符输入流(可以实现char类型数据的读取)
public int read (char[] cbuf) throw IOException 读取多个字符,返回读取的个数
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/13852784.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地