Here you can find the source of save(File file, String content)
Parameter | Description |
---|---|
file | the file to save to |
content | the content to save |
public static boolean save(File file, String content)
//package com.java2s; /*/* www .j av a2 s . c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class Main { /** * Saves the content to a file. * * @param file the file to save to * @param content the content to save * @return true if successfully saved */ public static boolean save(File file, String content) { boolean result; BufferedWriter writer; writer = null; try { writer = new BufferedWriter(new FileWriter(file)); writer.write(content); writer.flush(); result = true; } catch (Exception e) { e.printStackTrace(); result = false; } finally { if (writer != null) { try { writer.close(); } catch (Exception e) { // ignored } } } return result; } }