Java file read/write class I wrote

Source: Internet
Author: User
  1. /** =================================================== =========================================== **
  2. * [## Public static void createcheckfile (string filepath, string detail) throws {}]:
  3. * Parameter: filepath file path name
  4. * Detail: content of the file to be written
  5. * Return value: None
  6. * Modifier: public static can directly call a method without instantiating an object.
  7. * Function: Write detail to a specified path file.
  8. ** ===================================================== ========================================= **/
  9. Public static void createcheckfile (string filepath, string detail) throws
  10. Exception {
  11. Try {
  12. File file = new file (filepath );
  13. Filewriter = new filewriter (file, false); // false indicates no content is appended.
  14. Filewriter. Write (detail );
  15. Filewriter. Close ();
  16. } Catch (ioexception e ){
  17. Throw E;
  18. } Catch (exception ex ){
  19. Throw ex;
  20. }
  21. }
  22. /** =================================================== =========================================== **
  23. * [## Public static string readcheckfile (string filepath) throws {}]:
  24. * Parameter: filepath file path name
  25. * Return value: None
  26. * Modifier: public static can directly call a method without instantiating an object.
  27. * Function: return the content in the specified path file.
  28. ** ===================================================== ========================================= **/
  29. Public static string readcheckfile (string filepath) throws exception {
  30. Bufferedreader bufread;
  31. String read, readstr;
  32. Readstr = "";
  33. Try {
  34. File file = new file (filepath );
  35. Filereader fileread = new filereader (File );
  36. Bufread = new bufferedreader (fileread );
  37. While (read = bufread. Readline ())! = NULL ){
  38. Readstr = readstr + read;
  39. }
  40. } Catch (exception d ){
  41. System. Out. println (D. getmessage ());
  42. }
  43. Return readstr; // return the content read from the text file.
  44. }
Related Article

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.