00001 package TxTPackage;
00002 import java.io.*;
00003 import java.util.*;
00004
00005
00016 public class DataFileToIntegers {
00017 public DataFileToIntegers(String datafile){
00018 try {
00019 String aLine,token;
00020
00021 FileInputStream fin = new FileInputStream(datafile);
00022 BufferedReader br = new BufferedReader(new InputStreamReader(fin));
00023
00024 while ((aLine = br.readLine()) != null) {
00025 StringTokenizer st2 = new StringTokenizer(aLine, " ");
00026 while(st2.hasMoreTokens()){
00027 token=st2.nextToken();
00028
00029 countEntries(token);
00030 }
00031
00032 }
00033
00034 Debug.print(aantal_v);
00035 Debug.print(aantal_f);
00036 v=new int[aantal_v][3];
00037 f=new int[aantal_f][3];
00038
00039 br.close();
00040
00041 FileInputStream fin2 = new FileInputStream(datafile);
00042 BufferedReader br2 = new BufferedReader(new InputStreamReader(fin2));
00043 aLine = br2.readLine();
00044
00045 while ((aLine=br2.readLine()) != null) {
00046 StringTokenizer st2 = new StringTokenizer(aLine, " ");
00047 token=st2.nextToken();
00048
00049 if(token.equals("v")){
00050 for (int i =0; i!=3;i++){
00051 token=st2.nextToken();
00052 Debug.print(token);
00053 v[v_teller][i]=(int)Float.parseFloat(token);
00054 }
00055 v_teller++;
00056 }else{
00057 if(token.equals("f")){
00058 for (int i =0; i!=3;i++){
00059 token=st2.nextToken();
00060
00061 f[f_teller][i]=Integer.parseInt(token);
00062 }
00063 f_teller++;
00064 }
00065 }
00066
00067
00068 }
00069 br2.close();
00070
00071 }
00072 catch (Exception e) {
00073 e.printStackTrace();
00074 }
00075 }
00076
00080 private int aantal_v=0;
00084 private int aantal_f=0;
00088 private int[][] v;
00092 private int[][] f;
00096 private int v_teller=0;
00100 private int f_teller=0;
00101 public void countEntries(String token){
00102 if(token.equals("v")){
00103 aantal_v++;
00104 }
00105 if(token.equals("f")){
00106 aantal_f++;
00107 }
00108 }
00109
00110
00111
00112
00113 public int[][] getv(){
00114 return v;
00115 }
00116
00117 public int[][] getf(){
00118 return f;
00119 }
00120
00121 public static void main (String args[]){
00122 DataFileToIntegers dataconv=new DataFileToIntegers("test.smf");
00123 Debug.print("print de gehele rij");
00124 Algorithms.ArrayHandler.printrij(dataconv.getv());
00125 Algorithms.ArrayHandler.printrij(dataconv.getf());
00126 }
00127 }