/* * * Copyright (c) 2006 by Know-Center, Graz, Austria * * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, * OR NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * $Id: FileHelper.java,v 1.2 2006/05/15 12:05:21 wlackner Exp $ */ package at.knowcenter.wag.egov.egiz.tools; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.FileReader; import java.io.FileWriter; import org.apache.log4j.Logger; import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger; /** * This class provides file reader and writer methods. All methods are static! * * @author wlackner */ public class FileHelper { /** * The logger definition. */ private static final Logger logger_ = ConfigLogger.getLogger(FileHelper.class); /** * This method reads a file by reading line by line. * * @param fileName the file to be read * @return the content string of the file */ public static String readFromFile(String fileName) { String file_string = null; try { BufferedReader reader = new BufferedReader(new FileReader(fileName)); String line = null; file_string = ""; while ((line = reader.readLine()) != null) { file_string += line; } reader.close(); } catch (FileNotFoundException e) { logger_.info("File not found:" + fileName); } catch (IOException e) { logger_.info("File can not read:" + fileName); } return file_string; } /** * This method writes a file line by line. * * @param fileName the file to be written * @param fileString the content to be written * @return true if the file could be written sucessfully, false otherwise */ public static boolean writeToFile(String fileName, String fileString) { BufferedWriter writer; try { FileWriter fwriter = new FileWriter(fileName); writer = new BufferedWriter(fwriter); writer.write(fileString); writer.close(); } catch (IOException e) { logger_.info("File:" + fileName + " can not be written. Cause:" + e.getMessage()); return false; } return true; } }