JAVA(IO流方法大全)

JAVA(IO流方法大全)

ID:37914435

大小:13.83 KB

页数:5页

时间:2019-06-02

JAVA(IO流方法大全)_第1页
JAVA(IO流方法大全)_第2页
JAVA(IO流方法大全)_第3页
JAVA(IO流方法大全)_第4页
JAVA(IO流方法大全)_第5页
资源描述:

《JAVA(IO流方法大全)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、packageStream;importjava.io.*;publicclassIo{publicvoidtest1()throwsException{  Filefile=newFile("E:/txt.txt");  if(file.exists()){      System.out.println("是否是文件:"+file.isFile());   System.out.println("文件名是:"+file.getName());   System.out.println("路径是

2、:"+file.getPath());   System.out.println("绝对路径是:"+file.getAbsolutePath());   System.out.println("上级目录是:"+file.getParent());   System.out.println("文件大小是:"+file.length()+"字节");  }  else{   file.createNewFile();  }}publicvoidtest2()throwsException{//以字节流

3、方式读取    Filefile=newFile("E:/txt1.txt");  FileInputStreamfi=newFileInputStream(file);  byte[]content=newbyte[fi.available()];      /*for(inti=0;i

4、t);//第二种方式    Stringstr=newString(content);       System.out.println(str.trim());}     publicvoidtest3()throwsException{//以字节流方式写入数据       Filefile=newFile("E:/txt1.txt");  FileOutputStreamfo=newFileOutputStream(file);  byte[]content=newString("你是一个")

5、.getBytes();  fo.write(content);  content=newString("呵呵").getBytes();  fo.write(content);  fo.close();     }          publicvoidtest4()throwsException{//用的缓冲方式文本读取          FileReaderfile=newFileReader("E:/txt1.txt");     BufferedReaderbr=newBufferedR

6、eader(file);             StringBufferstr=newStringBuffer();     Stringsw=br.readLine();     if(sw!=null){      str.append(sw+"");       }     System.out.println(str);     }     publicvoidtest5()throwsException{//用缓冲的方式写入数据然后再读入数据     FileWriterfile=

7、newFileWriter("E:/txt1.txt");     BufferedWriterbw=newBufferedWriter(file);     for(inti=1;i<=10;i++){            bw.write("这是第"+i+"行");      bw.newLine();     }     bw.close();//写放数据          FileReaderfile1=newFileReader("E:/txt1.txt");     Buffered

8、Readerbr=newBufferedReader(file1);     StringBufferstr=newStringBuffer();     Stringsw=br.readLine();     if(sw!=null){            str.append(sw+"");             }     System.out.println(str);     }          publicvoidtest6(){//删除文件     File

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。