欢迎来到课桌文档! | 帮助中心 课桌文档-建筑工程资料库
课桌文档
全部分类
  • 党建之窗>
  • 感悟体会>
  • 百家争鸣>
  • 教育整顿>
  • 文笔提升>
  • 热门分类>
  • 计划总结>
  • 致辞演讲>
  • 在线阅读>
  • ImageVerifierCode 换一换
    首页 课桌文档 > 资源分类 > DOCX文档下载  

    Java毕业设计外文翻译.docx

    • 资源ID:1463612       资源大小:23.56KB        全文页数:11页
    • 资源格式: DOCX        下载积分:5金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要5金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Java毕业设计外文翻译.docx

    毕业设计(论文)外文文献翻译译文:JavaI/O系统对编程语言的设计者来说,创建,套好的输入输出(I/O)系统,是一项难度极高的任务。这一类可以从解决方案的数母之多上看出端倪。这个问题就难在它要面对的可能性太多了。不仅是因为有那么多的I/O的源和目的(文件,限制台,网络连接等等),而且还有许多方法(依次的,随机的,缓存的,二进制的,字符方式的,行的,字的等等)。Java类库的设计者们用“仓犍许多类”的方法来解决这个问题。坦率地说,JaVal/0系统的类实在太多了,以至于初看起来会把人吓着(但是,具有讽剌意味的是,这种设计事实上是限制了类的爆炸性增长此外,Java在1.0版之后又对其I/O类库进行了重大的修改,原先是面对byle的,现在又补充r面对CniCode字符的类库。为提高性能,完善功能,JDKl.4又加/一个nio(意思是“newI/O"。这个名字会用上许多年)。这么以来,假如你想对Java的I/O类库有个全面了解,并且做到运用白如,你就得先学习大量的类。此外,了解I/O类库的演化历史也是相当玳要的。可能你的第反应是“别拿什么历史来烦我了,告知我怎么用就可以了!”但问题是,假如你对这段一窍不通,很快就会被一些有用或是没用的类给搞糊涂了。本文会介绍JaVa标准类库中的各种I/O类,与其运用方法。File类在介绍干腌从流里读写数据的类之前,我们先介绍一下处理文件和书目的类。你会认为这是一个关于文件的类,但它不是。你可以用它来表示某个文件的名字,也可以用它来表示书目里一组文件的名字。假如它表示的是一组文件,那么你还可以用list()方法来进行查询,让它会返回Slring数组。由于元素数量是固定的,因此数组会比容器更好一些。假如你想要获得另一个书1.l的清单,再建一个File对象就是了。书目列表器假设你想看看这个书目。有两个方法。一是不带参数调用list().它返回的是FilO对象所含内容的完整清单。但是,假如你要的是一个"限制性列表还是书目,以与删除文件。rena11eTo()这个方法会把文件重命名成(或者说移动到)新的书目,也就是参数所给出的书目。而参数本身就是一个FiIe对象。这个方法也适用于书目。输入与输出I/O类库常运用"流(Stream)”这种抽象。所谓"流"是一种能生成或接受数据的,代表数据的源和目标的对象。流把I/O设备内部的详细操作给隐微起来了。正如JDK文档所示的,Java的I/O类库分成输入和输出两大部分。全部InpulStreain和Reader的派生类都有一个基本的,继承下来的,能读取单个或byte数组的read()方法。同理,全部OutputStream和Writer的派生类都有一个基本的,能写入单个或byte数组的Write()方法。但通常状况下,你是不会去用这些方法的;它们是给其它类用的一一而后者会供应些更好用的接口。因此,你很少会遇到只用一个类就能创建一个流的情形,事实上你得把多个对象桎起来,并以此来获得所需的功能。Java的流类库之所以会那么让人犯旱,最主要的缘由就是"你必需为创建一个流而动用多个对象,我们最好还是依据其功能为这些class归个类。JaVa1.0的类库设计者们是从确定“让全部与输入相关的类去继承InPUIStream”入手的。同理,全部与输出相关的类就该继承OutputStream了。添加属性与适用的接口运用"分层对象(IayCredobjects)”,为单个对象动态地,透亮地添加功能的做法,被称为DecoralorPatterne(模式是ThinkinginPatterns(withJaVa)的主题。)Decoraor模式要求全部包覆在原始对象之外的对象,都必需具有与之完全相同的接口。这使得decorator的用法变得特别的透亮一无论对象是否被decorate过,传给它的消息总是相同的。这也是JaVal/0类库要有"filter(过滤器)”类的缘由:抽象的"filter”类是全部decorator的基类。(decorator必需具有与它要包装的对象的全部接口,但是decorator可以扩展这个接口,由此就衍生出了许多"filler"类)。Decorator模式常用于如下的情形:假如用继承来解决各种需求的话,类的数量会多到不切实际的地步。Java的I/O类库须要供应许多功能的组合,J:是decorator模式就有了用武之地。但是decorator有个缺点,在提高编程的敏捷性的同时(因为你能很简单地混合和匹配属性),也使代码变得更困难了。Java的1/0类库之所以会这么怪,就是因为它"必需为一个1/0对象创建许多类”,也就是为一个"核心"I/O类加上许多decoratoro为InputStream和OutputStreani定义decorator类接口的类,分别是FiIterInputStream和FilterOutputStreamo这两个名字都起得不怎么样。FiIterInputStream和FilterOutputStream都继承自I/O类库的基类InputStream和OutputStrcani,这是decorator模式的关键(惟有这样decorator类的接口才能与它要服务的对象的完全相同)。用FilterInPUtStream读取InputStreamFilterInputStream与其派牛类有两项重要任务。DataInputStream可以读取各种PrimitiVe与String,(全部的方法都以"read"打头,比11readByte(),readFloat()它,以与它的搭档DataOUtPUtStreanb能让你通过流将primitive数据从一个地方导到另一个地方。这些"地方”都列在表12-4里。其它的类都是用来修改InPUtSIream的内部行为的:是不是做缓冲,是不是知道它所读取的行信息.(允许你读取行号或设定行号),是不是会弹出单个字符。后两个看上去更像是给编译器用的(也就是说,它们也许是为Java编译器设计的),所以通常状况下,你是不大会用到它们的。不论你用哪种1/0设备,输入的时候,最好都做缓冲.所以对"0类库来说,比校明智的做法还是把不缓冲当特例(或者去干脆调用方法),而不是像现在这样把缓冲当作特例。外文原文:JAVA1/0SystemGreatingagoodinput/output(I/O)systemisoneofthemoredifficulttasksforthelanguagedesigner.Thisisevidencedbythenumberofdifferentapproaches.Thechallengeseemstobeincoveringal1eventualities.NotonlyaretheredifferentsourcesandsinksofI/Othatyouwanttocommunicatewith(files,theconsole,networkconnections),butyouneedtotalktotheminawidevarietyofways(sequential,random-access,buffered,binary,character,by1ines,bywords,etc.).TheJava1ibrarydesignersattackedthisproblembycreatinglotsofclasses.Infact,therearesomanyclassesforJava'SI/Osystemthatitcanbeintimidatingatfirst(ironically,theJavaI/Odesignactuallypreventsanexplosionofclasses).Therewasalsoasignificantchangeinthe1/0libraryafterJava1.0,whentheoriginalbyte-oriented1ibrarywassupplementedwithchar-oriented,Unicode-basedI/Oclasses.AsaresultthereareafairnumberofclassestolearnbeforeyouunderstandenoughofJava,SI/Opicturethatyoucanuseitproperly.Inaddilion,it,SratherimportanttounderstandtheevolutionhistoryoftheI/Olibrary,evenifyourfirstreactionis"don'tbothermewithhistory,justshowmehowtouseit!"Theproblemisthatwithoutthehistoricalperspectiveyouwillrapidlybecomeconfusedwithsomeoftheclassesandwhenyoushouldandshouldn,tusethem.ThisarticlewillgiveyouanintroductiontothevarietyofI/OclassesinthestandardJava1ibraryandhowtousethem.TheFileclassBeforegettingintotheclassesthatactualIyreadandwritedatatostreams,we'11lookautilityprovidedwiththelibrarytoassistyouinhandlingfiledirectoryissues.TheFileclasshasadeceivingname-youmightthinkitreferstoafile,butitdoesn,t.11canrepresenteiIherthenameofaparticularfileorthenamesofasetoffilesinadirectory.Ifit,Sasetoffiles,youcanaskfortheseiwiththe1ist()method,andthisreturnsanarrayofString.Itmakessensetoreturnanarrayratherthanoneoftheflexiblecontainerclassesbecausethenumberofelementsisfixed,andifyouwantadifferentdirectorylistingyoujustcreateadifferentFileobject.Infact,“FilePalh"wouldhavebeenabetternamefortheclass.Thissectionshowsanexampleoftheuseofthisclass,includingtheassociatedFilenameFilterinterface.AdirectorylisterSupposeyou'dliketoseeadirectorylisting.ThePileobjectcanbe1istedintwoways.Ifyoucalllist()withnoarguments,you,11gettheful1listthattheFiIeobjectcontains.However,ifyouwantarestrictedlist-forexample,ifyouwantallofthefileswithanextensionof.java-thenyouuseadirectoryfi1ter,"whichisaclassthattellshowtoselecttheFileobjectsfordisplay.TheDirFilterclass"inplemenls"theinterfaceFilenameFilter.It'susefultoseehowsimpletheFilenameFilterinterfaceis:publicinterfaceFilenameFillerbooleanaccept(Filetiir,Stringname);Theaccept()methodmustacceptaFileobjectrepresentingthedirectorythataparticularfileisfoundin,andaStringcontainingthenameofthatfile.YoumightchoosetouseorignoreeiIherofthesearguments,butyouwillprobablyatleastusethefilename.Rememberthatthe1ist()methodiscallingaccept()loreachofthefilenamesinthedirectoryobjecttoSeewhichoneshouldbeincluded-thisisindicatedbythebooleanresultreturnedbyaccept().Tomakesuretheelementyou,reworkingwithisonlythefilenameandcontainsnopathinformation,al1youhavetodoistaketheStringobjectandcreateaFileobjectoutofit,thencallgetName(),whichstripsawayal1thepathinformation(inaplatform-independenIway).Thenaccept()usesthearegularexpressionmatcherobjecttoseeiftheregularexpressionregexmatchesthenameofthefile.UsingacceptO,theIistOmethodreturnsanarray.AnonynousinnerclassesThisexampleisidealforrewritingusingananonymousinnerclass.safirstcul,amethodfi1ter()iscreatedthatreturnsareferencetoaFilenameFilter:/Usesanonymousinnerclasses.importjava.io.*:importjava,util.*;importcom.bruceeckel.util.*;publicclassDir1.ist2(publicstaticFilenameFilterfilter(finalStringafn)/Creationofanonym。USinnerclass:returnnewFiIenameFillerOl.Stringfn=afn;publicbooleanaccept(Filedir,Siringn)(/Strippathinformation:Stringf=newFile(n).getName();returnf.indexf(fn)!=-1:);/Endofanonymousinnerclasspublicstaticvoidmain(Stringargs)Filepath=newFile(".");Stringlist;if(args,length=0)list=path,list():elselist=path.1ist(filter(args0j);Arrays,sort(list,newAlphabeticComparatorO);for(inti=O:i<list,length:i+)System,out.println(listi):Notethattheargumenttofilter()mustbefinal.Thisisrequiredbytheanonymousinnerclasssothatitcanuseanobjectfromoutsideitsscope.ThisdesignisanimprovementbecausetheFilenameFilterclassisnowtightlyboundtoDir1.ist2.However,youcantakethisapproachonestepfurtheranddefinetheanonymousinnerclassasanargumenttolist(),inwhichcaseit,sevensmaller:/Buildingtheanonymousinnerclass”in-place.”importjava.io.*:importjava.util.*;importcom.bruceeckel.util.*;publicclassDir1.ist3publicstaticvoid11ain(finalSlringargs)Filepath=newFiIeStringlist:if(args,length=0)list=path.IislO:elselist=path.1isi(newFilenameFiIter()(publicbooleanaccept(Filedir,Siringn)(StringfnewFile(n).getName():returnf.indexf(args0)!=-1;Arrays,sort(list,newAlphabelicComparatorO):for(inti=O;i<list.length;i+)System,out.println(listi);Theargumenttomain()isnowfinal,sincetheanonymousinnerclassusesargs0jdirectly.Thisshowsyouhowanonymousinnerclassesallowthecreationofquick-and-(iirtyclassestosolveproblems.SinceeverythinginJavarevolvesaroundclasses,thiscanbeausefulcodingtechnique.OnebenefitisthatiIkeepsthecodethatsolvesaparticularproblemisolatedtogetherinonespot.Ontheotherhand,itisnotalwaysaseasytoread,soyoumustuseitjudiciously.CheckingforandcreatingdirectoriesTheFiIeclassismorethanjustarepresentationforanexistingfiIeordirectory.YoucanalsouseaFiIeobjecttocreateanewdirectoryoranentiredirectorypathifitdoesn,texist.Youcanalsolookatthecharacteristicsoffiles(size,lastmodificationdate,read/Write),seewhetheraFileobjectrepresentsafiIeoradirectory,anddeleteafile.Thefirstmethodthat'sexercisedbymain()isrenameTo(),whichallowsyoutorename(ormove)afiletoanentirelynewpathrepresentedbytheargument,whichisanotherFileobject.Thisalsoworkswithdirectoriesofanylength.InputandoutputI/Olibrariesoftenusetheabstractionofastream,whichrepresentsanydatasourceorsinkasanobjectcapableofproducingorreceivingpiecesofdata.ThestreamhidesthedetailsofwhathappenstothedatainsidetheactualI/Odevice.TheJava1ibraryclassesforI/Oaredividedbyinputandoutput,asyoucanseebylookingaltheonlineJavaclasshierarchyintheJDKdocumentation.Byinheritance,everythingderivedfromtheInputStreamorReaderclasseshavebasicmethodscalledread()forreadingasinglebyteorarrayofbytes.1.ikewise,everythingderivedfromOutputStreamorWriterclasseshavebasicmethodscalledwrite()forwritingasinglebyteorarrayofbytes.However,youwon'tgenerallyusethesemethods:theyexistsothatotherclassescanusethem-theseotherclassesprovideamoreusefulinterface.Thus,you,11rarelycreateyourstreamobjectbyusingasingleclass,bulinsteadwilllayermultipleobjectstogethertoprovideyourdesiredfunctionality.ThefactthatyoucreatemorethanoneobjecttocreateasingleresultingstreamistheprimaryreasonthatJava,Sstream1ibraryisconfusing.It,shelpfultocategorizetheclassesbytheirfundionality.InJava1.0,thelibrarydesignersstartedbydecidingthatallclassesthathadanythingtodowithinputwouldbeinheritedfromInputStreamandallclassesthatwereassociatedwithoutputwouldbeinheritedfromOutputStream.AddingattributesandusefulinterfacesTheuseoflayeredobjectstodynamicallyandtransparentlyaddresponsibilitiestoindividualobjectsisreferredtoastheDecoratorpattern.Thedecoratorpatternspecifiesthatal1objectsthatwraparoundyourinitialobjecthavethesameinterface.Thismakesthebasicuseofthedecoratorstransparent-yousendthesamemessagetoanobjectwhetherit,Sbeendecoratedornot.Thisisthereasonfortheexistenceofthe"filler"classesintheJavaI/Olibrary:theabstract“filter“classisthebaseclassforallthedecorators.(Adecoratormusthavethesameinterfaceastheobjectitdecorates,bulthedecoratorcanalsoextendtheinterface,whichoccursinseveralofthe"filler"classes).Decoratorsareoftenusedwhensimplesubclassingresultsinalargenumberofsubclassesinordertosatisfyeverypossiblecombinationthatisneeded-somanysubclassesthatitbecomesimpractical.TheJavaI/Olibraryrequiresmanydifferentcombinationsoffeatures,whichiswhythedecoratorpatternisused.Thereisadrawbacktothedecoratorpattern,however.DecoratorsgiveyoumuchmoreflexibilitywhiIeyou,rewritingaprogram(sinceyoucaneasilymixandmatchattributes),buttheyaddcomplexitytoyourcode.ThereasonthattheJavaI/O1ibraryisawkwardtouseisthatyoumustcreatemanyclasses-the"core"I/Otypeplusallthedecorators-inordertogetthesingleI/Oobjectthatyouwant.TheclassesthatprovidethedecoratorinterfacetocontrolaparticularInputStreamorOutputStreamaretheFilterInputStreaniandFiIterOuIputStream-whichdon,thaveveryintuitivenames.FilterInputStreamandFilterOutputStreamareabstractclassesthatarederivedfromthebaseclassesoftheI/O1ibrary,InputStreamandOutputStream,whichisthekeyrequirementofthedecorator(sothatitprovidesthecommoninterfacetoalltheobjectsthatarebeingdecorated).ReadingfromanInputStreamwithFilterInputStreaDTheFilterInputStreaniclassesaccomplishtwosignificantlydifferentthings.DataInputStreamallowsyoutoreaddifferenttypesofprimitivedataaswellasStringobjects.(Allthemethodsstartwith"read,“suchasreadByt(),readFloat(),etc.)This,alongwithiIscompanionDataOutputStreajn,allowsyoutomoveprimitivedatafromoneplacetoanotherviaastream.These“places"aredeterminedbytheclassesinTable12-4Table12-1.TypesofFilterInputStreanTheremainingclassesmodifythewayanInputStreambehavesinternally:whetherit,Sbufferedorunbuffered,ifitkeepstrackofthelinesit'sreading(allowingyoutoaskforlinenumbersorsetthelinenumber),andwhetheryoucanpushbackasinglecharacter.Thelasttwoclasseslookalot1ikesupportforbuiIdingaconpiIer(thatis,theywereaddedtosupporttheconstructionoftheJavacompiler),soyouprobablywon'tusethemingeneralprogramming.You,11probablyneedtobufferyourinputalmosteverytime,regardlessoftheI/Odeviceyou,reconnectingto,soitwou1dhavemademoresensefortheI/Olibrarytomakeaspecialcase(orsimplyamethodcall)forunbufferedinputratherthanbufferedinput.

    注意事项

    本文(Java毕业设计外文翻译.docx)为本站会员(夺命阿水)主动上传,课桌文档仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知课桌文档(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-1

    经营许可证:宁B2-20210002

    宁公网安备 64010402000986号

    课桌文档
    收起
    展开