public static void textToBinary ( String featuresFolder , final String featureType , int featureLength ) throws Exception { // read the folder containing the description files File dir = new File ( featuresFolder ) ; FilenameFilter filter = new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { if ( name . endsWith ( "." + featureType ) ) return true ; else return false ; } } ; String [ ] files = dir . list ( filter ) ; for ( int i = 0 ; i < files . length ; i ++ ) { if ( i % 100 == 0 ) { System . out . println ( "Converting file " + i ) ; } BufferedReader in = new BufferedReader ( new FileReader ( new File ( featuresFolder + files [ i ] ) ) ) ; DataOutputStream out = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ( featuresFolder + files [ i ] + "b" ) ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { String [ ] nums = line . split ( "," ) ; for ( int j = 0 ; j < featureLength ; j ++ ) { out . writeDouble ( Double . parseDouble ( nums [ j ] ) ) ; } } in . close ( ) ; out . close ( ) ; } }
Takes a folder with feature files in text format and converts them to binary .