Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class Databank_Handling {
- FileOutputStream fout = null;
- FileInputStream fin = null;
- File f = null;
- Databank_Handling(String filePath){
- f = new File(filePath);
- try
- {
- //fout = new FileOutputStream(f);
- fin = new FileInputStream(f);
- }
- catch (IOException e)
- {
- System.err.println ("Unable to open file");
- System.exit(-1);
- }
- }
- Databank_Handling(File filePath){
- f = filePath;
- try
- {
- fout = new FileOutputStream(f);
- fin = new FileInputStream(f);
- }
- catch (IOException e)
- {
- System.err.println ("Unable to open file");
- System.exit(-1);
- }
- }
- protected void finalize(){
- try {
- fout.close();
- } catch (IOException e) {
- System.err.println ("Unable to close file");
- System.exit(-1);
- }
- }
- public void writeInDatabank(String str){
- byte b[] = new byte[str.length()];
- for(int qq = 0; qq < str.length(); qq++)
- b[qq] = (byte)str.charAt(qq);
- try {
- fout.write(b);
- } catch (IOException e) {
- System.err.println ("Unable to write to file");
- System.exit(-1);
- }
- }
- public String readInDatabank(){
- String str = new String();
- byte b[] = new byte[(int)f.length()];
- try {
- fin.read(b);
- } catch (IOException e) {
- System.err.println ("Unable to write to file");
- System.exit(-1);
- }
- for(int qq = 0; qq < f.length(); qq++)
- str += (char)b[qq];
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement