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 读取多个字符,返回读取的个数