2013年6月11日 星期二

二進位檔案

bio
binary.txt
  pH?腲I?毨 !D-
import java.io.*;

class bio{
 public static void main(String[] args) throws IOException
 {

  DataInputStream din= new DataInputStream (
   new BufferedInputStream(
    new FileInputStream("binary.txt")));
  long n1=din.readLong();
  int n2=din.readInt();
  double n3=din.readDouble();
  System.out.println(" n1: "+n1+" n2: "+n2+" n3: "+n3);
  din.close();
 }
}

tio
text.txt
12345678901234512345678903.141592653589793
import java.io.*;

class tio{
 public static void main(String[] args) throws IOException
 {

      FileReader fr1=new FileReader("text.txt"); 
  BufferedReader bfr1= new BufferedReader(fr1);
  String str;
  
  while ((str=bfr1.readLine())!=null) //  
  {
   long n1=Long.parseLong(str.substring(0,15));
   int n2=Integer.parseInt(str.substring(15,25));
   double n3=Double.parseDouble(str.substring(25));
   System.out.println(" n1: "+n1+" n2: "+n2+" n3: "+n3);
  }
  fr1.close();
 }
}

沒有留言:

張貼留言