Here you can find the source of writeFile(String FileName, String data)
Parameter | Description |
---|---|
FileName | name of file to create |
data | date to write |
public static boolean writeFile(String FileName, String data)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/* w w w. j a v a2s . c o m*/ * { method * * @param FileName name of file to create * @param data date to write * @return true = success * } * @name writeFile * @function write the string data to the file Filename */ public static boolean writeFile(String FileName, String data) { try { PrintWriter out = openPrintWriter(FileName); if (out != null) { out.print(data); out.close(); return (true); } return (false); // failure } catch (SecurityException ex) { return (false); // browser disallows } } /** * { method * * @param FileName name of file to create * @param data date to write * @return true = success * } * @name writeFile * @function write the string data to the file Filename */ public static boolean writeFile(File TheFile, String data) { PrintWriter out = null; try { out = openPrintWriter(TheFile); if (out != null) { out.print(data); out.close(); return (true); } return (false); // failure } catch (SecurityException ex) { return (false); // browser disallows } finally { if (out != null) out.close(); } } /** * { method * * @param name name of file * @return the stream - null for failure * } * @name openPrintWriter * @function open a PrintWriter to a file with name */ public static PrintWriter openPrintWriter(String name) { FileOutputStream file = null; try { file = new FileOutputStream(name); return new PrintWriter(new BufferedOutputStream(file)); } catch (SecurityException ee) { return (null); } catch (IOException ee) { return (null); } } /** * { method * * @param name name of file * @return the stream - null for failure * } * @name openPrintWriter * @function open a PrintWriter to a file with name */ public static PrintWriter openPrintWriter(File name) { FileOutputStream file = null; try { file = new FileOutputStream(name); return new PrintWriter(new BufferedOutputStream(file)); } catch (SecurityException ee) { return (null); } catch (IOException ee) { return (null); } } }