File to create txt files

Source: Internet
Author: User

    • /**
  • * Generate Data files
  • *
  • * @param the path to the FilePath write file
  • * @param content written in the contents of the string
  • * @return
  • */
  • public boolean Writerfile (string content, string url) {
  • Boolean flag = true;
  • try{
  • //Create file object with parameter string type, indicating directory name
  • File MyFile = new file (URL);
  • //Determine if the file exists, call the CreateNewFile () method to create a new directory if it does not exist, or skip to exception handling code
  • if (!myfile.exists ())
  • myfile.createnewfile ();
  • else{//throws an exception if it does not exist
  • Flag = false;
  • throw new Exception ("The new file already exists!");
  •    }
  • //write the data to the created file, first create the FileWriter object with the new file name parameter
  • FileWriter resultfile = new FileWriter (myFile);
  • //Wrap the object into the Printerwriter object
  • PrintWriter mynewfile = new PrintWriter (resultfile);
  • //The string data is then written to the new file by the println () method of the Printerwriter object
  • mynewfile.println (content);
  • resultfile.close (); Close File Write stream
  • }catch (Exception ex) {
  • System.out.println ("Could not create new file! ");
  • flag = false;
  • }
  • return flag ;
  • }

File to create txt files

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.