Here you can find the source of writeStringToFile(String stringToWrite, String fileName)
Parameter | Description |
---|---|
stringToWrite | The string used to generate the text file. |
fileName | Name it whatever you want. |
public static File writeStringToFile(String stringToWrite, String fileName)
//package com.java2s; /*//w ww . ja v a 2 s . c o m * 2010, http://github.com/pauloewerton/partSOM4Grid * This file is part of partSOM4Grid * * partSOM4Grid is free software: you can redistribute it and/or modify it under the * terms of the Artistic License 2.0 as published by the OSI. * * This program is distributed in hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the Artistic License 2.0 * for more details. * * You should have received a copy of the Artistic License 2.0 * along with this program. See <www.opensource.org/licenses/artistic-license-2.0>. * */ import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { /** * Writes a string (generated from running the previous method) on a plain * text file. * @param stringToWrite The string used to generate the text file. * @param fileName Name it whatever you want. **/ public static File writeStringToFile(String stringToWrite, String fileName) { File file = new File(fileName); FileWriter writer = null; try { writer = new FileWriter(file); writer.write(stringToWrite); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } return file; } }