Implementing the CreateFile() Method
The Method CreateFile() is defined in the class, File_class. This method is used to create a new file. The CreateFile() method creates file with the name FileOutput.txt. The method also catches the error, if the file is not opened.
public void CreateFile()
{
try
{
Of = new DataOutputStream(new FileOutputStream("FileOut.txt"));
Of.writeChars("Beginn");
}
catch(IOException e)
{
System.err.println("File not opened properlyn"+e.toString());
System.exit(1);
}
}
The above listing shows the declaration of the CreateFile() method. The CreateFile() method creates a filed named FileOuput.txt. The CreateFile() method also throws an IOException exception.
Implementing the addtofile() is defined in the class, File_class. This method is used to append the file. The method uses the string method, str.length() to calculate the lenght of the string.
Declaration of the method, addTofile()
public void addTofile(String str)
{
try
{
for(int i=str.length()-1;i>=0;i--)
{
Of.writeChar(str.charAt(i));
Of.writeChars("n");
}
Of.writeChar('E');
Of.writeChars("n");
}
catch (IOException io){}
}
The above listing shows the declaration of the addTofile() method. The addTofile() mehthod appends an existing file.
Implementating the delFile() Method
The method, delFile() is defined in the class, File_class. This method is used to delete the existing file formthe permanent storage.
public void delFile()
{
CreateFile();
try
{
Of.close();
}
catch (IOException io){}
}
The above listing shows the declration of the delFile() method. The delFile() method closes the existing opened file.
The Method CreateFile() is defined in the class, File_class. This method is used to create a new file. The CreateFile() method creates file with the name FileOutput.txt. The method also catches the error, if the file is not opened.
public void CreateFile()
{
try
{
Of = new DataOutputStream(new FileOutputStream("FileOut.txt"));
Of.writeChars("Beginn");
}
catch(IOException e)
{
System.err.println("File not opened properlyn"+e.toString());
System.exit(1);
}
}
The above listing shows the declaration of the CreateFile() method. The CreateFile() method creates a filed named FileOuput.txt. The CreateFile() method also throws an IOException exception.
Implementing the addtofile() is defined in the class, File_class. This method is used to append the file. The method uses the string method, str.length() to calculate the lenght of the string.
Declaration of the method, addTofile()
public void addTofile(String str)
{
try
{
for(int i=str.length()-1;i>=0;i--)
{
Of.writeChar(str.charAt(i));
Of.writeChars("n");
}
Of.writeChar('E');
Of.writeChars("n");
}
catch (IOException io){}
}
The above listing shows the declaration of the addTofile() method. The addTofile() mehthod appends an existing file.
Implementating the delFile() Method
The method, delFile() is defined in the class, File_class. This method is used to delete the existing file formthe permanent storage.
public void delFile()
{
CreateFile();
try
{
Of.close();
}
catch (IOException io){}
}
The above listing shows the declration of the delFile() method. The delFile() method closes the existing opened file.
0 Comments:
Post a Comment