8 package org.bitstorm.util;
10 import java.awt.FileDialog;
11 import java.awt.Frame;
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
43 textFileReader = null;
44 textFileWriter = null;
53 public EasyFile( URL url )
throws IOException {
55 textFileWriter = null;
58 textFileReader = url.openStream();
67 public EasyFile( Frame parent, String title ) {
70 textFileReader = null;
71 textFileWriter = null;
79 public EasyFile( InputStream textFileReader ) {
81 textFileWriter = null;
90 public EasyFile( OutputStream textFileWriter ) {
92 textFileReader = null;
104 if ( textFileReader == null ) {
105 if ( filepath == null ) {
106 FileDialog filedialog =
new FileDialog( parent, title, FileDialog.LOAD );
107 filedialog.setFile( filename );
109 if ( filedialog.getFile() != null ) {
110 filename = filedialog.getFile();
111 filepath = filedialog.getDirectory()+
filename;
115 textFileReader =
new FileInputStream( filepath );
118 StringBuffer text =
new StringBuffer();
122 while ( ( bytesRead = textFileReader.read( buffer, 0, bufferLength ) ) != -1 )
123 text.append(
new String( buffer, 0, bytesRead ) );
125 textFileReader.close();
127 return text.toString();
134 public void writeText( String text )
throws IOException {
135 if ( textFileWriter == null ) {
136 if ( filepath == null ) {
137 FileDialog filedialog =
new FileDialog( parent, title, FileDialog.SAVE );
138 filedialog.setFile( filename );
140 if ( filedialog.getFile() != null ) {
141 filename = filedialog.getFile();
142 filepath = filedialog.getDirectory()+
filename;
143 if ( fileExtension != null && filepath.indexOf(
'.') == -1 ) {
149 textFileWriter =
new FileOutputStream( filepath );
153 textFileWriter.write( text.getBytes() );
155 textFileWriter.close();
172 return filename == null ? filepath :
filename;
EasyFile(InputStream textFileReader)
EasyFile(String filepath)
OutputStream textFileWriter
void setFileExtension(String s)
void setFileName(String s)
void writeText(String text)
InputStream textFileReader
EasyFile(OutputStream textFileWriter)
EasyFile(Frame parent, String title)