Example usage for java.io FileReader read

List of usage examples for java.io FileReader read

Introduction

In this page you can find the example usage for java.io FileReader read.

Prototype

public int read() throws IOException 

Source Link

Document

Reads a single character.

Usage

From source file:CopyCharacters.java

public static void main(String[] args) throws IOException {
    FileReader inputStream = null;
    FileWriter outputStream = null;

    try {/*w  ww.  j  av a2  s  .  c om*/
        inputStream = new FileReader("xanadu.txt");
        outputStream = new FileWriter("characteroutput.txt");

        int c;
        while ((c = inputStream.read()) != -1) {
            outputStream.write(c);
        }
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:yax.test.TestOptions.java

static String getinput(String filename) throws IOException {
    StringBuilder buf = new StringBuilder();
    FileReader file = new FileReader(filename);
    int c;/*from   w  ww  .ja v  a 2  s .  co m*/

    while ((c = file.read()) > 0) {
        buf.append((char) c);
    }
    return buf.toString();
}

From source file:org.wso2.carbon.registry.registry.extensions.utills.FileManagerUtills.java

public static void copyFile(File sourceFile, String destinationPath) throws IOException {
    File destinationFile = new File(destinationPath);

    FileReader in = new FileReader(sourceFile);
    FileWriter out = new FileWriter(destinationFile);
    int c;/*from   w  ww  .j av  a 2 s  .c  o  m*/

    while ((c = in.read()) != -1)
        out.write(c);

    in.close();
    out.close();
}

From source file:Util.commont.Config.java

public static void initConfig(Plash plash) {
    FileReader fr = null;
    try {//  w  w w .jav  a 2  s.  c o m
        File f = new File("resource/uiConfig.json");
        fr = new FileReader(f);
        String jsonStr = "";
        int k;
        while ((k = fr.read()) != -1)
            jsonStr += (char) k;
        JSONObject obj = new JSONObject(jsonStr);
        colorP = obj.getString("colorP");
        colorS = obj.getString("colorS");
        colorT = obj.getString("colorT");
        height = obj.getString("height");
        width = obj.getString("width");
        type = obj.getString("type");
        logo = obj.getString("logo");
        year_version = obj.getString("year_version");
        copyright = obj.getString("copyright");
        appName = obj.getString("appName");
        plash.init();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            fr.close();
        } catch (IOException ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.sonatype.nexus.test.utils.FileTestingUtils.java

public static void fileCopy(File from, File dest) throws IOException {
    // we may also need to create any parent directories
    if (dest.getParentFile() != null && !dest.getParentFile().exists()) {
        dest.getParentFile().mkdirs();/*w w  w. j a  v a 2  s  .com*/
    }

    FileReader fileReader = new FileReader(from);

    FileWriter fos = new FileWriter(dest);

    int readChar = -1;
    while ((readChar = fileReader.read()) != -1) {
        fos.write(readChar);
    }

    // close everything
    fileReader.close();
    fos.close();
}

From source file:org.wso2.esb.integration.common.utils.common.FileManager.java

public static void copyFile(File sourceFile, String destinationPath) throws IOException {
    File destinationFile = new File(destinationPath);

    FileReader in = new FileReader(sourceFile);
    FileWriter out = new FileWriter(destinationFile);
    int c;/*from   w  w w .  j  a v a 2 s  .co  m*/
    try {
        while ((c = in.read()) != -1) {
            out.write(c);
        }
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            //ignore
        }
        try {
            out.close();
        } catch (IOException e) {
            //ignore
        }
    }

}

From source file:com.netcrest.pado.internal.security.AESCipher.java

private static byte[] getUserPrivateKey() throws IOException {
    byte[] privateKey = null;

    String estr;//from   www .  jav  a2s  .c o m
    String certificateFilePath = PadoUtil.getProperty(Constants.PROP_SECURITY_AES_USER_CERTIFICATE,
            "security/user.cer");
    if (certificateFilePath.startsWith("/") == false) {

        // TODO: Make server files relative to PADO_HOME also.
        if (PadoUtil.isPureClient()) {
            String padoHome = PadoUtil.getProperty(Constants.PROP_HOME_DIR);
            certificateFilePath = padoHome + "/" + certificateFilePath;
        }
    }
    File file = new File(certificateFilePath);
    if (file.exists() == false) {
        FileWriter writer = null;
        try {
            privateKey = AESCipher.getPrivateKey();
            Base64 base64 = new Base64(0); // no line breaks
            estr = base64.encodeToString(privateKey);
            writer = new FileWriter(file);
            writer.write(estr);
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    } else {
        FileReader reader = null;
        try {
            reader = new FileReader(file);
            StringBuffer buffer = new StringBuffer(2048);
            int c;
            while ((c = reader.read()) != -1) {
                buffer.append((char) c);
            }
            estr = buffer.toString();
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
    Base64 base64 = new Base64(0); // no line breaks
    privateKey = base64.decode(estr);
    return privateKey;
}

From source file:com.endofhope.neurasthenia.bayeux.BayeuxMessage.java

private static String getString(String location) throws IOException {
    StringBuilder sb = new StringBuilder();
    FileReader fr = new FileReader(location);
    int oneInt = -1;
    while (-1 != (oneInt = fr.read())) {
        sb.append((char) oneInt);
    }/*from  w ww. j  a  v  a 2 s  . c o  m*/
    fr.close();
    return sb.toString();
}

From source file:edu.clemson.lph.utils.CSVParserWrapper.java

private static void stripNewLines(File fIn, File fOut) {
    FileReader rIn = null;
    FileWriter wOut = null;/*from  w  w  w .  j a va2 s  .  com*/
    try {
        rIn = new FileReader(fIn);
        wOut = new FileWriter(fOut);
        int iQuoteCount = 0;
        char cLast = '\0';
        char cThis = '\0';
        int iThis = rIn.read();
        while (iThis >= 0) {
            cThis = (char) iThis;
            if (cThis == '\"') {
                iQuoteCount++;
            }
            if (cThis == '\n' || cThis == '\r') {
                if ((iQuoteCount % 2) > 0) {
                    //               System.err.println("Removed new line after " + iQuoteCount + " quotes");
                    //               new Exception("Removed new line after " + iQuoteCount + " quotes").printStackTrace();
                    //               System.exit(1);
                    cThis = ' ';
                } else {
                    iQuoteCount = 0;
                }
            }
            wOut.append(cThis);
            cLast = cThis;
            iThis = rIn.read();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        logger.error(e);
    } finally {
        try {
            if (rIn != null)
                rIn.close();
            if (wOut != null) {
                wOut.flush();
                wOut.close();
            }
        } catch (IOException e) {
            logger.error(e);
        }
    }
}

From source file:es.csic.iiia.planes.cli.Cli.java

/**
 * Parse the provided list of arguments according to the program's options.
 * //from w  w  w  . ja  va2 s. co m
 * @param in_args
 *            list of input arguments.
 * @return a configuration object set according to the input options.
 */
private static Configuration parseOptions(String[] in_args) {
    CommandLineParser parser = new PosixParser();
    CommandLine line = null;
    Properties settings = loadDefaultSettings();

    try {
        line = parser.parse(options, in_args);
    } catch (ParseException ex) {
        Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        showHelp();
    }

    if (line.hasOption('h')) {
        showHelp();
    }

    if (line.hasOption('d')) {
        dumpSettings();
    }

    if (line.hasOption('s')) {
        String fname = line.getOptionValue('s');
        try {
            settings.load(new FileReader(fname));
        } catch (IOException ex) {
            throw new IllegalArgumentException("Unable to load the settings file \"" + fname + "\"");
        }
    }

    // Apply overrides
    settings.setProperty("gui", String.valueOf(line.hasOption('g')));
    settings.setProperty("quiet", String.valueOf(line.hasOption('q')));
    Properties overrides = line.getOptionProperties("o");
    settings.putAll(overrides);

    String[] args = line.getArgs();
    if (args.length < 1) {
        showHelp();
    }
    settings.setProperty("problem", args[0]);

    Configuration c = new Configuration(settings);
    System.out.println(c.toString());
    /**
     * Modified by Guillermo B. Print settings to a result file, titled
     * "results.txt"
     */
    try {
        FileWriter fw = new FileWriter("results.txt", true);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter out = new PrintWriter(bw);
        String[] results = c.toString().split("\n");
        // out.println(results[8]);

        for (String s : results) {
            out.println(s);

        }
        // out.println(results[2]);
        // out.println(results[8]);
        out.close();
    } catch (IOException e) {
    }

    /**
     * Modified by Ebtesam Save settings to a .csv file, titled
     * "resultsCSV.csv"
     */

    try {
        FileWriter writer = new FileWriter("resultsCSV.csv", true);
        FileReader reader = new FileReader("resultsCSV.csv");

        String header = "SAR Strategy,# of Searcher UAVs,# of Survivors,"
                + "# of Survivors rescued,Min.Time needed to rescue Survivors,Mean. Time needed to rescue Survivors,Max. Time needed to rescue Survivors,"
                + "# of Survivors found,Min. Time needed to find Survivors,Mean Time needed to find Survivors,Max. Time needed to find Survivors,"
                + "Running Time of Simulation\n";
        if (reader.read() == -1) {
            writer.append(header);
            writer.append("\n");
        }
        reader.close();
        String[] results = c.toString().split("\n");
        writer.append(results[2].substring(10));
        writer.append(",");
        writer.append(results[20].substring(11));
        writer.append(",");
        writer.append(results[30].substring(18));
        writer.write(",");
        writer.close();
    } catch (IOException e) {
    }

    if (line.hasOption('t')) {
        System.exit(0);
    }
    return c;
}