public static void binaryToText ( 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 + "b" ) ) 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 ) ; } DataInputStream in = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( featuresFolder + files [ i ] ) ) ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( new File ( featuresFolder + files [ i ] . replace ( "b" , "" ) ) ) ) ; long counter = 0 ; while ( true ) { try { double val = in . readDouble ( ) ; out . write ( String . valueOf ( val ) ) ; } catch ( EOFException e ) { break ; } counter ++ ; if ( counter % featureLength == 0 ) { out . write ( "\n" ) ; } else { out . write ( "," ) ; } } in . close ( ) ; out . close ( ) ; } }
Takes a folder with feature files in binary format and converts them to text .