import java.net.URL; import java.net.URLConnection; import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; class fil7_c { public fil7_c( URL url ) throws IOException { URLConnection url_conn = url.openConnection(); BufferedReader reader = new BufferedReader( new InputStreamReader( url_conn.getInputStream() ) ); this.read_file( reader ); } // ordfil_c public fil7_c( String filnamn ) throws IOException, FileNotFoundException { File fil = new File( filnamn ); BufferedReader reader = new BufferedReader( new FileReader( fil ) ); this.read_file( reader ); } // ordfil_c public String[] raderna() { return this.rad_vek; } // orden private void read_file( BufferedReader reader ) throws IOException { // Lagra först i lokal variabel // Gard mot att det är färre än 7 rader i filen String [] lokal_vek = new String[7]; int antal = 0; do { lokal_vek[antal] = reader.readLine(); if ( lokal_vek[antal] == null ) { break; /////////// End of file } antal++; } while ( antal < 7 ); reader.close(); this.rad_vek = new String[antal]; for ( int index = 0; index < antal; index++ ) { this.rad_vek[index] = lokal_vek[index]; } } // read_file private String rad_vek[]; } // fil7_c