Java Utililty Methods BufferedReader Copy

List of utility methods to do BufferedReader Copy

Description

The list of methods to do BufferedReader Copy are organized into topic(s).

Method

voidcopyFile(BufferedReader in, BufferedWriter out)
copy File
while (true) {
    String line = in.readLine();
    if (line == null) {
        break;
    out.write(line);
    out.newLine();
    out.flush();
...
voidcopyFile(File from, File to)
copy File
Reader reader = new BufferedReader(new FileReader(from));
Writer writer = new BufferedWriter(new FileWriter(to));
int ch;
while ((ch = reader.read()) != -1) {
    writer.write(ch);
reader.close();
writer.close();
...
voidcopyFile(File orgFile, File dstFile)
Copy orgFile in dstFile
InputStream is = new FileInputStream(orgFile);
FileOutputStream fos = new FileOutputStream(dstFile);
byte[] readData = new byte[1024];
int i = is.read(readData);
while (i != -1) {
    fos.write(readData, 0, i);
    i = is.read(readData);
is.close();
fos.close();
voidcopyFile(File original, File copy)
This method copies the provided file.
if (!original.exists()) {
    return;
createFile(copy);
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(original)));
PrintWriter pw = new PrintWriter(new FileWriter(copy));
try {
    String line = br.readLine();
...
voidcopyFile(File source, File dest)
change the dest's opengraph id from OG to file path
BufferedReader br = new BufferedReader(new FileReader(source));
BufferedWriter bw = new BufferedWriter(new FileWriter(dest));
String result = "";
try {
    while ((result = br.readLine()) != null) {
        String a = dest.getName().replaceAll("\\.", "_");
        result = result.replaceAll("OG_", a);
        bw.write(result + "\r\n");
...
voidcopyFile(File src, File dst)
Copies a file.
if (src.isFile()) {
    if (!src.exists()) {
        throw new Exception("Source File does not exist");
    if (!dst.exists()) {
        if (!dst.createNewFile()) {
            throw new Exception("Could not create Destination File");
    if (dst.isFile() && dst.canWrite()) {
        Writer output = new BufferedWriter(new FileWriter(dst));
        output.write(getContents(src));
        output.close();
    } else {
        throw new Exception("Problem writing file: " + dst);
} else {
    throw new Exception("Util: Invalid File Provided");
voidcopyFile(String orig, String dest)
copy File
copyFile(new File(orig), new File(dest));
voidcopyFile(String source, String dest)
Copies a file from one location to another
File s = new File(source);
File d = new File(dest);
copyFile(s, d);
voidcopyFile(String src, String dst)
Copy a text file
BufferedReader inFile = null;
PrintWriter outFile = null;
String line;
try {
    inFile = new BufferedReader(new FileReader(src));
    outFile = new PrintWriter(new FileOutputStream(dst));
    while ((line = inFile.readLine()) != null)
        outFile.println(line);
...
booleancopyFile(String src, String dst)
copy File
if (src == null || dst == null) {
    return false;
return writeTextToFile(getTextFromFile(src), dst);