1019 Classroom Content

Source: Internet
Author: User
Tags readfile

1  Packagetext;2 3 ImportJava.io.*;4 5 //text file Operation class6  Public classfile {7     8     PrivateString FileName;9     Ten      PublicString GetFileName () One     { A         returnFileName; -     } -     //Construction the     Privatefile file; -      -      Publicfile (String fileName) -     { +          This. FileName =FileName; -          +File =NewFile (fileName); A     } at          -         //Create a file -          Public voidCreate ()throwsIOException -         { -               -              in             if(!file.exists ())//If the file does not exist -             { to file.createnewfile (); +System.out.println ("File creation succeeded! "); -             } the             Else *             { $System.out.println ("File already exists! ");Panax Notoginseng             } -         } the         //Deleting Files +          Public voidDelete () A         { theFile File =NewFile (fileName); +              -             if(File.exists ())//If the file exists $             { $ File.delete (); -System.out.println ("Delete succeeded! "); -             } the             Else -             {WuyiSYSTEM.OUT.PRINTLN ("file does not exist!) "); the             } -         } Wu         //Modify Content -          Public voidEdit (String stredit)throwsIOException//the modifications are transferred in the form of parameters . About         { $             if(File.exists ()) -             { -FileWriter FW =NewFileWriter (file); -                  ABufferedWriter BFW =NewBufferedWriter (FW); +                  the Bfw.write (stredit); -                  $ bfw.close (); the             } the             Else the             { theSYSTEM.OUT.PRINTLN ("file does not exist!) "); -             } in         } the         //Append Content the          Public voidAddLine (String strLine)throwsIOException//Add new lines, and transfer content About         { the             if(File.exists ()) the             { theString str =readFile (); +                  -FileWriter FW =NewFileWriter (file); the                 BayiBufferedWriter BFW =NewBufferedWriter (FW); the                  the                 //bfw.newline (); -                  -Bfw.write (str+ "\ n" +strLine); the                  the bfw.close (); the             } the             Else -             { theSYSTEM.OUT.PRINTLN ("file does not exist!) "); the             } the         }94          PublicString ReadFile ()throwsIOException the         { theString RTN = ""; the             98             if(File.exists ()) About             { -FileReader FR =Newfilereader (file);101                 102BufferedReader br =NewBufferedReader (FR);103                 104String s = ""; the                 106                  while((s = br.readline ())! =NULL)107                 {108Rtn + = s + "\ n";109                 } the br.close ();111             } the             Else113             { theSYSTEM.OUT.PRINTLN ("file does not exist!) "); the             } the             returnRtn;117         }118}
View Code

1019 Classroom Content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.