Advertisement
GraionDilach

Untitled

Oct 31st, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4.  
  5.  
  6. public class MainIO {
  7.  
  8.     /**
  9.      * @param args
  10.      */
  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.        
  14.         try {
  15.             FileInputStream TestExample = new FileInputStream("d:/zimmgy/IOex1.txt");
  16.             FileOutputStream TestExampleCopy = new FileOutputStream("d:/zimmgy/IOex11.txt");
  17.            
  18.             int c;         
  19.             while ((c = TestExample.read()) != -1){
  20.                 TestExampleCopy.write(c);
  21.             }
  22.            
  23.             TestExample.close();
  24.             FileInputStream TestExample2 = new FileInputStream("d:/zimmgy/IOex1.txt");
  25.             FileOutputStream TestExampleCopy2 = new FileOutputStream("d:/zimmgy/IOex12.txt");
  26.            
  27.             byte[] buf = new byte[10];
  28.             while ((c =TestExample2.read(buf)) == buf.length){
  29.                 TestExampleCopy2.write(buf);
  30.             }
  31.             TestExampleCopy2.write(buf, 0, c);
  32.            
  33.             FileInputStream TestExample3 = new FileInputStream("d:/zimmgy/IOex1.txt");
  34.             FileOutputStream TestExampleCopy3 = new FileOutputStream("d:/zimmgy/IOex13.txt");
  35.             byte[] fullbuf = new byte[TestExample3.available()];
  36.             TestExample3.read(fullbuf);
  37.             TestExampleCopy3.write(fullbuf);
  38.            
  39.             FileInputStream TestExample21 = new FileInputStream("d:/zimmgy/IOex2.txt");
  40.             byte[] recordbuf = new byte[512];
  41.             TestExample21.skip(512);
  42.             while ((c =TestExample21.read(recordbuf)) == recordbuf.length){
  43.                 System.out.println(new String(recordbuf));
  44.             }
  45.             System.out.println(new String(recordbuf, 0, c));
  46.            
  47.             FileInputStream TestExample31 = new FileInputStream("d:/zimmgy/IOex3.txt");
  48.             System.out.println("Fájlméret: " + TestExample31.available());
  49.             byte[] buffor3 = new byte[TestExample31.available()/4];
  50.             TestExample31.read(buffor3);
  51.             System.out.println(new String(buffor3));
  52.             System.out.println("Hátravan: " + TestExample31.available());
  53.             byte[] buffor32 = new byte[buffor3.length/2];
  54.             System.out.println(new String(buffor32));
  55.             TestExample31.skip(buffor3.length);
  56.             c =TestExample31.read(buffor3);
  57.             System.out.println(new String(buffor3, 0, c));
  58.         } catch (Exception e) {
  59.             /*
  60.              * FileOutputStream BackupTest = new FileOutputStream("d:/zimmgy/IOex1.txt");
  61.              * FileInputStream TestExample = new FileInputStream("d:/zimmgy/IOex1.txt");
  62.              */
  63.         }
  64.  
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement