I am trying to experiment with the whole idea of creating two text files then write to one of them, rename the second file with the first file and then deleting the first file. I have a school project where i need to apply this concept. So, before i actually applied the concept in my project, I tried to experiment with a rough code. Now, everything works fine except that the second file doesn't contain the data from the first file. How do i fix this problem?

This is my class which is called potpie:-

package project4;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class potpie {

    PrintWriter out,cr;

    File file1 = new File("trial.txt");
    File file2 = new File("item.txt");

    public void createfile() throws IOException
        out = new PrintWriter(new FileWriter(file1,true));

        out.println("User1" + "639755");

        cr = new PrintWriter(new FileWriter(file2,true));



I am getting blank output in my trial.txt file and i don't know where i made the mistake. Please help me out.

Well, I don't think you are writing to cr. You create it, and then close it, but nothing is written to it.