/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* User: andy
* Date: 30/07/2006
* Time: 08:37
*/
package uk.org.aspellclark.common.file;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AsciiFileWriter extends AsciiFile {
protected OutputStreamWriter osw;
protected BufferedWriter buffrdWtr;
/**
* writes a text line out to the file and appends a newline to the end of it
*
* @param psLine
*/
public final void WriteLine(final String psLine) {
try {
buffrdWtr.write(psLine);
buffrdWtr.write("\n");
} catch (IOException ex) {
Logger.getLogger(AsciiFileWriter.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* writes a text line out to the file
*
* @param psLine
*/
public final void Write(final String psLine) {
try {
buffrdWtr.write(psLine);
} catch (IOException ex) {
Logger.getLogger(AsciiFileWriter.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* opens the file ready for writing
*/
public final void openFile() {
try {
osw = new FileWriter(m_sFilepath + m_sFilename);
// FileOutputStream of =
// android.content.Context.openFileOutput(this.m_sFilename,
// android.content.Context.MODE_WORLD_READABLE);
buffrdWtr = new BufferedWriter(osw);
} catch (FileNotFoundException ex) {
Logger.getLogger(AsciiFileReader.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ioex) {
Logger.getLogger(AsciiFileReader.class.getName()).log(Level.SEVERE, null, ioex);
}
}
public final void closeFile() {
try {
buffrdWtr.close();
osw.close();
} catch (IOException ex) {
Logger.getLogger(AsciiFileWriter.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
|