private String get_username_for_id ( String publicId , String filename ) throws FileNotFoundException { Scanner sc = null ; File file = new File ( filename ) ; try { sc = new Scanner ( file ) ; while ( sc . hasNextLine ( ) ) { String line = sc . nextLine ( ) ; if ( line . startsWith ( "yk." + publicId + ".user" ) ) { String ykuser = line . split ( "=" ) [ 1 ] . trim ( ) ; return ykuser ; } } } finally { if ( sc != null ) { sc . close ( ) ; } } return null ; }
Given publicId vvcccccfhc scans filename for a line like yk . vvcccccfhc . user = alice and returns alice if found . Null is returned in case there is no matching line in file .