欢迎来到天天文库
浏览记录
ID:15707793
大小:65.50 KB
页数:17页
时间:2018-08-05
《java文件操作大全》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、java文件操作大全获得控制台用户输入的信息Java代码/***//**获得控制台用户输入的信息*@return*@throwsIOException*/publicStringgetInputMessage()throwsIOException...{System.out.println("请输入您的命令∶");bytebuffer[]=newbyte[1024];intcount=System.in.read(buffer);char[]ch=newchar[count-2];//最后两位为结束符,删去不要fo
2、r(inti=0;i3、(buffer);char[]ch=newchar[count-2];//最后两位为结束符,删去不要for(inti=0;i4、n*/publicvoidcopyFile(Stringsrc,Stringdest)throwsIOException...{FileInputStreamin=newFileInputStream(src);Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.re5、ad(buffer))!=-1)...{for(inti=0;i6、Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.read(buffer))!=-1)...{for(inti=0;i7、多种类型,比如txt,xml,jpg,doc等多种格式三.写文件1.利用PrintStream写文件Java代码/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStream(out);for(inti=0;i<10;i++)p.println("Thisis"+i+"line");}catch(FileN8、otFoundExceptione)...{e.printStackTrace();}}/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStrea
3、(buffer);char[]ch=newchar[count-2];//最后两位为结束符,删去不要for(inti=0;i4、n*/publicvoidcopyFile(Stringsrc,Stringdest)throwsIOException...{FileInputStreamin=newFileInputStream(src);Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.re5、ad(buffer))!=-1)...{for(inti=0;i6、Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.read(buffer))!=-1)...{for(inti=0;i7、多种类型,比如txt,xml,jpg,doc等多种格式三.写文件1.利用PrintStream写文件Java代码/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStream(out);for(inti=0;i<10;i++)p.println("Thisis"+i+"line");}catch(FileN8、otFoundExceptione)...{e.printStackTrace();}}/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStrea
4、n*/publicvoidcopyFile(Stringsrc,Stringdest)throwsIOException...{FileInputStreamin=newFileInputStream(src);Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.re
5、ad(buffer))!=-1)...{for(inti=0;i6、Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.read(buffer))!=-1)...{for(inti=0;i7、多种类型,比如txt,xml,jpg,doc等多种格式三.写文件1.利用PrintStream写文件Java代码/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStream(out);for(inti=0;i<10;i++)p.println("Thisis"+i+"line");}catch(FileN8、otFoundExceptione)...{e.printStackTrace();}}/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStrea
6、Filefile=newFile(dest);if(!file.exists())file.createNewFile();FileOutputStreamout=newFileOutputStream(file);intc;bytebuffer[]=newbyte[1024];while((c=in.read(buffer))!=-1)...{for(inti=0;i7、多种类型,比如txt,xml,jpg,doc等多种格式三.写文件1.利用PrintStream写文件Java代码/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStream(out);for(inti=0;i<10;i++)p.println("Thisis"+i+"line");}catch(FileN8、otFoundExceptione)...{e.printStackTrace();}}/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStrea
7、多种类型,比如txt,xml,jpg,doc等多种格式三.写文件1.利用PrintStream写文件Java代码/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStream(out);for(inti=0;i<10;i++)p.println("Thisis"+i+"line");}catch(FileN
8、otFoundExceptione)...{e.printStackTrace();}}/***//***文件输出示例*/publicvoidPrintStreamDemo()...{try...{FileOutputStreamout=newFileOutputStream("D:/test.txt");PrintStreamp=newPrintStrea
此文档下载收益归作者所有