/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.javaone.scrambler;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jirka
 */
public class File2String {
    public static String file2string (File f) {
        StringBuilder out = new StringBuilder();
        try {
            BufferedReader in = new BufferedReader(new FileReader(f));
            String l = null;
            try {
                while ((l = in.readLine()) != null) {
                    out.append(l);
                }
            } catch (IOException ex) {
                Logger.getLogger(File2String.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                in.close();
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(File2String.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(File2String.class.getName()).log(Level.SEVERE, null, ex);
        }
        return out.toString();
    }
}
