I am supposed to Write a java program to open a text file. First I have to Check if the file already exists. If the file already exists then append data to it. Otherwise program should write 10 lines of text data in the file.
Can anyone else check to see if this is right, i did this using Notepad

<font size=2><pre>

import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.BufferedReader;
import java.lang.String;
import java.io.IOException;
import java.io.FileWriter;

public class textfile {

public textfile() {
}
public int FileWrite(String FileName) //method that takes a string as parameters
{
PrintWriter OutFile = null;
try
{
OutFile = new PrintWriter(new FileOutputStream(FileName));
}
catch(FileNotFoundException e)
{
System.out.println("Error in creating the file" + FileName);
System.exit(1);
}
System.out.println("Type in 10 lines of text");
for(int i=1;i<11;i++)
{
String Lines;
Lines = ReadInput.ReadLine();
OutFile.println(Lines);
}
OutFile.close();
System.out.println("Stored the lines in the file:" + FileName);
return 0;
}
public int AppendFile(String FileName)
{
PrintWriter OutFile = null;
try
{
OutFile = new PrintWriter(new FileOutputStream(FileName, true));
}
catch(FileNotFoundException e)
{
System.out.println("Errorin finding or creating the file" + FileName);
System.exit(1);
}
System.out.println("Type in 10 more lines of text");

for(int i=1; i<11;i++)
{
String Lines;
Lines = ReadInput.ReadLine();
OutFile.println(Lines); //takes input from User
}
OutFile.close();
System.out.println("File saved"); //assurance of the file saved
return 0;
}
public void ReadFile(String FileName)
{
String Lines = null;
try
{
BufferedReader Infil = new BufferedReader(new FileReader(FileName));
Lines = InFile.readLine();
while(Lines !=null) // this While loop is used to print out the contents of the file
{ System.out.println(Lines);
Lines = InFile.readLine();
}
InFile.close();
}
catch(FileNotFoundException e)
{
System.out.println("Error opening file or file not found " + e); //prints file not found
System.exit(1);
}
catch (IOException e)
{
System.out.println("Error reading file from " + FileName + e); //prints error message
}
}

public static void main(String[] args) {
textfile CFile = new textfile();
CFile.FileWrite("C:\\NewFile.txt"); //when file exitsts call this method
CFile.AppendFile("C:\\NewFile.txt");//calls Appendfile method
CFile.ReadFile("C:\\NewFile.txt"); // calls Readfile method

}
}

}

</pre></font>