Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5.  
  6.  
  7. public class Databank_Handling {
  8.    
  9.     FileOutputStream fout = null;  
  10.     FileInputStream fin = null;
  11.     File f = null;
  12.  
  13.     Databank_Handling(String filePath){
  14.         f = new File(filePath);
  15.         try
  16.         {
  17.             //fout = new FileOutputStream(f);
  18.             fin = new FileInputStream(f);
  19.         }
  20.         catch (IOException e)
  21.         {
  22.             System.err.println ("Unable to open file");
  23.             System.exit(-1);
  24.         }
  25.     }
  26.    
  27.     Databank_Handling(File filePath){
  28.         f = filePath;
  29.         try
  30.         {
  31.             fout = new FileOutputStream(f);
  32.             fin = new FileInputStream(f);
  33.         }
  34.         catch (IOException e)
  35.         {
  36.             System.err.println ("Unable to open file");
  37.             System.exit(-1);
  38.         }
  39.     }
  40.    
  41.     protected void finalize(){
  42.         try {
  43.             fout.close();
  44.         } catch (IOException e) {
  45.             System.err.println ("Unable to close file");
  46.             System.exit(-1);
  47.         }
  48.     }
  49.    
  50.     public void writeInDatabank(String str){
  51.         byte b[] = new byte[str.length()];
  52.         for(int qq = 0; qq < str.length(); qq++)
  53.             b[qq] = (byte)str.charAt(qq);
  54.         try {
  55.             fout.write(b);
  56.         } catch (IOException e) {
  57.             System.err.println ("Unable to write to file");
  58.             System.exit(-1);
  59.         }
  60.     }
  61.    
  62.     public String readInDatabank(){
  63.         String str = new String();
  64.         byte b[] = new byte[(int)f.length()];
  65.         try {
  66.             fin.read(b);
  67.         } catch (IOException e) {
  68.             System.err.println ("Unable to write to file");
  69.             System.exit(-1);
  70.         }
  71.         for(int qq = 0; qq < f.length(); qq++)
  72.             str += (char)b[qq];
  73.         return str;
  74.     }
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement