private boolean importFlatFile ( String sender ) { boolean result = false ; try { List < String > file = new ArrayList <> ( ) ; String str ; while ( ( str = flatFileReader . readLine ( ) ) != null ) { file . add ( str ) ; } flatFileReader . close ( ) ; List < User > userList = new ArrayList <> ( ) ; for ( String aFile : file ) { String [ ] info = aFile . split ( " " ) ; try { double balance = Double . parseDouble ( info [ 1 ] . split ( ":" ) [ 1 ] ) ; userList . add ( new User ( info [ 0 ] , balance ) ) ; } catch ( NumberFormatException e ) { Common . getInstance ( ) . sendConsoleMessage ( Level . SEVERE , "User " + info [ 0 ] + " have a invalid balance" + info [ 1 ] ) ; } catch ( ArrayIndexOutOfBoundsException e ) { Common . getInstance ( ) . sendConsoleMessage ( Level . WARNING , "Line not formatted correctly. I read:" + Arrays . toString ( info ) ) ; } } addAccountToString ( sender , userList ) ; result = true ; } catch ( IOException e ) { Common . getInstance ( ) . getLogger ( ) . severe ( "A error occured while reading the iConomy database file! Message: " + e . getMessage ( ) ) ; } return result ; }
Import accounts from a flatfile .