I'm supposed to be reading data from a file and dumping part of it into another text file. But I'm having an error : <p>//the code below is constantly giving me errors since its not reading the file
public static void main(String[]args) throws IOException{</p>

<pre><code>    String file="marc21.txt";
    String a;

    BufferedReader br=new BufferedReader(new FileReader(file));
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("marc22.txt")));

        while(br.readLine()!=null){
            //obtaining first five characters of file
            file.substring(0, 4);
            //saving substring to value
            a=file.substring(0, 4);

            //converting a to integer
            int x=Integer.parseInt(a);
            System.out.println("x is "+x);

            //taking record to marc21 to another file marc22
            bw.write(file.substring(0, x));
            bw.write("\n");
            bw.close();

        }
</code></pre>
