try like this below code:
String fileName = "temp.txt";
String NewfileName = "New_temp.txt";
String FileContent = "";
String line = null;
try
{
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null)
{
FileContent = line;
}
bufferedReader.close();
}
catch(IOException ex)
{
System.out.println("Error reading file '" + fileName + "'" + ex.printStackTrace());
}
try
{
FileWriter fileWriter =new FileWriter(NewfileName);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(FileContent);
bufferedWriter.close();
}
catch(IOException ex)
{
System.out.println("Error Writing file '" + NewfileName + "'" + ex.printStackTrace());
}