软件开发重要黑马复习代码总结_第1页
软件开发重要黑马复习代码总结_第2页
软件开发重要黑马复习代码总结_第3页
软件开发重要黑马复习代码总结_第4页
软件开发重要黑马复习代码总结_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

importimportpublicclassSystemDemopublicstaticvoidmain(String[]{Propertiespro=for(Objectobj:pro.keySet())Stringvalue=(String)pro.get(obj); }System.setProperty("mykey1"iamfwj");StringvSystem.getProperty("haha");}} 获取系统属性信息:PropertiesimportimportpublicclassRuntimeDemopublicstaticvoidmain(String[]args)throwsExceptionRuntimer=Runtime.getRuntime();}}Runtime该方式是staticRuntimegetRuntime();importimportimportimportpublicclassDateDemopublicstaticvoidmain(String[]{Dated=newDate();SimpleDateFormatsdf=newSimpleDateFormat("yyyyMMddStringtime=sdf.format(d);longnowtime=System.currentTimeMillis();Datenowdate=newDate(nowtime);}}importimportpublicclassCalendarDemopublicstaticvoidmain(String[]args)Calendarintintintint}}年privateprivatestaticvoidGet_February_days()//TODOAuto-generatedmethodstubCalendarc=Calendar.getInstance();c.set(2008,2,1);c.add(Calendar.DAY_OF_MONTH,-1);}详细总结importimportjava.io.FileWriter;importjava.io.IOException;publicclassFileWriterDemo{publicstaticvoidmain(String[]args)throwsException//TODOAuto-generatedmethodFileWriterfw=newfw.write("lala}}构造函数中第二参数带false,写入时覆盖现有内容,进行续写默认为falsefw.write("lalafw.write("lalaimportimportclass{publicstaticvoidmain(String[]{FileWriterfw=null;{fw=newFileWriter("demo.txt");}catch(IOException{}{{}catchcatch(IOException{}}}}importimportimportpublicclassFileReaderDemopublicstaticvoidmain(String[]args)throwsExceptionFileReaderfr=newFileReader("filewriter.txt");int1){}}}importimportpublicclassFileReaderDemo2publicstaticvoidmain(String[]args)throws{FileReaderfr=newchar[]buf=newchar[1024];intch=0;}}}{FileReaderfr=newFileReader("filewriter.txt");FileWriterfw=newFileWriter("file_copy.txt");intch=0;1){}}privateprivatestaticvoidcopy_2()throwsIOException//TODOAuto-generatedmethodFileReaderfr=newFileReader("filewriter.txt");FileWriterfw=newFileWriter("file_copy2.txt");char[]buf=newchar[1024];int1){}}privateprivatestaticvoidcopy_3()//TODOAuto-generatedmethodstubFileReaderfr=null;FileWritertryfw=newFileWriter("file_3.txt");int1){}}catch(IOExceptione)//TODOAuto-generatedcatchthrownewRuntimeException("读写失败}ry{}catch(IOExceptione)//TODOAuto-generatedcatchthrownewRuntimeException("关闭文件读入流失败败}}ry{}catch(IOExceptione)//TODOAuto-generatedcatch}}}}importimportpublicclassBufferedWriterDemopublicstaticvoidmain(String[]args)throwsException//TODOAuto-generatedmethodFileWriterfw=newBufferedWriterbfw=newBufferedWriter(fw);for(inti=0;i<5;i++)}}}BuffedredBuffedrednewlineimportpublicclassCopyTextByBufpublicstaticvoidmain(String[]{FileReaderfr=null;FileWriterfw=null;BufferedReaderbfr=null;BufferedWriterbfw=null;try{fr=newfw=newFileWriter("copytextbybuf.txt");bfr=newBufferedReader(fr);bfw=newBufferedWriter(fw);Stringline=null;while((line=bfr.readLine())}}catch(Exceptione)//TODOAuto-generatedcatchthrownewRuntimeException("文件读写异常}finallyif(bfr!=null)try}catch(IOExceptione)//TODOAuto-generatedcatch}}}if(bfw!=null)try}catch(IOExceptione)//TODOAuto-generatedcatch}}}}}importimportpublicclassLineNumberdomepublicstaticvoidmain(String[]args)throws{FileReaderfr=newFileReader("file.txt");LineNumberReaderlfr=newLineNumberReader(fr);Stringline=null;while((line=lfr.readLine())!={System.out.println(lfr.getLineNumber()+":"+}}}importimportclassMyBufferedReaderextends{privateReaderr;{this.r=}publicStringmyReadLine()throws{StringBuildersb=newintch={return}return}publicintread(char[]cbuf,intoff,intlen)throws{returnr.read(cbuf,off,len)}publicvoidclose()throws{}publicvoidmyClose()throws{}}publicclass{publicstaticvoidmain(String[]args)throws{FileReaderfr=newFileReader("file.txt");MyBufferedReadermyBuf=newMyBufferedReader(fr);Stringline=null;{{}}}privateprivatestaticvoidWriteFile_1()throwsException//TODOAuto-generatedmethodFileOutputStreamfop=newFileOutputStream("fileout.txt");fop.write("woshiyigexiaolongren".getBytes());fop.write("我是汉字".getBytes());}privateprivatestaticvoidReadFile_1()throwsException//TODOAuto-generatedmethodFileInputStreamfis=newintch={}}FileInputStreamprivateprivatestaticvoidReadFile_2()throwsException//TODOAuto-generatedmethodFileInputStreamfis=newintbytebuf=newbyte[fis.available()];System.out.println(newString(buf));}}importimportpublicclassCopyPicpublicstaticvoidmain(String[]args)throwsException//TODOAuto-generatedmethodFileInputStreamfis=newFileInputStream("pic.png");FileOutputStreamfos=newFileOutputStream("pic_copy.png");intlen=0;byte[]buf=newbyte[1024];}}}importimportpublicclassCopyMp3publicstaticvoidmain(String[]args)throwsException BufferedOutputStreambfos=newnewintby=while((by=bfis.read())!=-{}}}注意盘符为publicclassReadinpublicstaticvoidmain(String[]args)throws{InputStreamin=System.in;StringBuildersb=newStringBuilder();while(true)intch=if(ch==if(ch=='\n')Strings=ifsb.delete(0,sb.length());}}}}publicpublicclassTransStreamDemopublicstaticvoidmain(String[]args)throwsExceptionInputStreamin=InputStreamReaderisr=newInputStreamReader(in);BufferedReaderbufr=newBufferedReader(isr);OutputStreamout=OutputStreamWriterOutputStreamWriterosw=newOutputStreamWriter(out);BufferedWriterbufw=newBufferedWriter(osw);Stringline=while((line=bufr.readLine())!=null)if}}}importimportpublicclassTransStreamDemo2publicstaticvoidmain(String[]args)throwsBufferedReaderbufrnewBufferedReader(newBufferedWriterbufw=newStringline=while((line=bufr.readLine())!=null)if}}}importimportjava.io.IOException;importjava.io.PrintStream;importjava.util.Date;publicclassExceptionInfopublicstaticvoidmain(String[]args)throws{{{int[]arr=newint[2];}catch(Exception{{Dated=newSimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-Strings=PrintStreamps=newPrintStream("exeception.log");}catch(IOException{thrownewRuntimeException("日志文件创建失败}}}}importimportimportimportpublicclassSystemInfopublicstaticvoidmain(String[]args)throws{Propertiespro=// pro.list(new}}建,返回false。booleanmkdir():创建文件夹。falsel。longlength()privateprivatestaticvoid{Filedir=newFile("D:\\");File[]files=dir.listFiles();for(Filef:files){}}privateprivatestaticvoidlistfileroots()//TODOAuto-generatedmethodstubFile[]roots=File.listRoots();for(Filef:roots){}}importimportpublicclasslistallfilespublicstaticvoidmain(String[]{Filedir=newshowDir(dir,}privatestaticvoidshowDir(Filedir,intlevel)//TODOAuto-generatedmethodstubFile[]for(File}}}}privatestaticStringgetlevel(intlevel)//TODOAuto-generatedmethodstubStringBuildersb=newStringBuilder();for(inti=0;i<level;{sb.insert(0,"|--}return}}注意:隐藏文件的问题importpublicclassremovedirdemopublicstaticvoidmain(String[]{Filedir=new}privatestaticvoidremovedir(Filedir)//TODOAuto-generatedmethodstubFile[]files=dir.listFiles();for(Filef:files)if(f.isDirectory())}elseif(f.isFile())}}}}}importimportjava.io.File;importjava.io.FileWriter;importjava.util.List;publicclassJavaFileListpublicstaticvoidmain(String[]args)throws{Filedir=newList<File>filelist=newArrayList<File>();}privatestaticvoidFilelist_to_txt(List<File>filelist)Exception//TODOAuto-generatedmethodBufferedWriterbufw=newBufferedWriter(newfor(int}}privatestaticvoidWriteFiletoList(Filedir,List<File>{//TODOAuto-generatedmethodstubFile[]files=dir.listFiles();for(Filef:files)}if(f.isFile()&&f.getName().endsWith(".txt")){filelist.a}}}////将info.txtprivatestaticvoidmethod_2()throwsIOException//TODOAuto-generatedmethod Propertiespro=newProperties();Stringline=null;String[]arr=line.split("=");}}importimportimportpublicpublicclassRunCountpublicstaticvoidmain(String[]args)throws{Filef=new}Propertiespro=newProperties();FileInputStreamfis=newFileInputStream(f);intStringnt(value);if(count>5){}}pro.setProperty("time",count+"");FileOutputStreamfos=newFileOutputStream(f);//load(InputStreamProperties表}}importimportjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.util.Enumeration;importjava.util.Vector;publicclassSequenceDemopublicstaticvoidmain(String[]args)throws{Vector<FileInputStream>v=v.add(newFileInputStream("file2.txt"));v.add(newFileInputStream("file2.txt"));v.add(newFileInputStream("file2.txt"));Enumeration<FileInputStream>en=v.elements();直到到达包含的最后一个输入流的文件末尾为止FileOutputStreamfos=newFileOutputStreambyte[]buf=newbyte[1024];intlen=0;}}}privateprivat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论