Java FileWriter Write saveToFile(String prefix, Reader input)

Here you can find the source of saveToFile(String prefix, Reader input)

Description

save To File

License

Apache License

Declaration

public static File saveToFile(String prefix, Reader input) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import java.io.Reader;

public class Main {
    /************************************************************************/
    public static File saveToFile(String prefix, Reader input) {
        File file;/* w  ww .j av a  2s.  c o  m*/
        BufferedWriter bw = null;
        try {
            file = File.createTempFile(prefix, null);
            bw = new BufferedWriter(new FileWriter(file));
            BufferedReader inputReader = new BufferedReader(input);
            String thisLine;
            while ((thisLine = inputReader.readLine()) != null) {
                bw.write(thisLine);
                bw.newLine();
            }
            inputReader.close();
        } catch (IOException e) {
            throw new RuntimeException("Unable to store order: " + e.getMessage(), e);
        } finally {
            try {
                if (bw != null) {
                    bw.close();
                }
            } catch (IOException e) {
            }
        }
        return file;
    }
}

Related

  1. saveToFile(List list, String filename, boolean append)
  2. saveToFile(String fileName, String resultStr)
  3. saveToFile(String fileName, String str)
  4. saveToFile(String location, File tempFile)
  5. saveToFile(String path, String line)
  6. saveToJson(Object object, String file)
  7. saveToTempFile(File folder, String content, String fileType)
  8. saveTreeStructuredGroupList(ArrayList> treeStructuredGroupList, String filePath)
  9. saveTxt(String line, String filename, boolean isEndSave)