17_4011_BALACHANDAR B
17_4011_BALACHANDAR B

Reputation: 11

FileOutputStream prints weird latin characters at the end in java

when I try copy a java file to txt file ,It works fine but it prints some additional lating character at end of output file(Note: there is no such latin character in input file). please refer the code

import java.io.*;
public class File1 {
    public static void main(String[] args) throws IOException {
    FileInputStream fin = null;
    FileOutputStream fout = null;
    int c;
    String input = "F:\\Java Intellij\\src\\testprint.java";
    String output = "F:\\Java Intellij\\src\\new23.txt";
    File infile = new File(input);
    File outfile = new File(output);
    infile.createNewFile();
    outfile.createNewFile();
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        fin = new FileInputStream(infile);
        fout = new FileOutputStream(outfile);

    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("enter :");


    if (fin != null && fout != null)
        try {
            do {

                c = fin.read();
                fout.write(c);
            } while (c != -1);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fin != null) {
                fin.close();
            }
            if (fout != null) {
                fout.close();
            }

        }
}

} can anyone shred some light on the question, why this happens??? and suggest a remedy

Upvotes: 1

Views: 35

Answers (0)

Related Questions