willbend Skrevet 11. mars 2005 Skrevet 11. mars 2005 Har tenkt å lese innholdet av en fil som ligger på nettet. Så hvorfor funker ikke denne: import java.io.*; import java.net.*; class dag { public static void main(String args[]) { if (args.length == 1) { try { FileInputStream fstream = new FileInputStream(" ....en txt fil som ligger på nettet "); DataInputStream in = new DataInputStream(fstream); while (in.available() !=0) { System.out.println (in.readLine()); } in.close(); } catch (Exception e) { System.err.println("File input error"); } } else System.out.println("Invalid parameters"); } }
Gjest Sletet+adslkfjv Skrevet 11. mars 2005 Skrevet 11. mars 2005 (endret) kanskje denne koden kan hjelpe deg litt, og så i samme slengen så er .readLine() Deprecated. void hentfil() throws ClassNotFoundException { try { ois = new ObjectInputStream(new FileInputStream(minfil)); while(true) { System.out.println(ois.readObject()); } } catch (FileNotFoundException e) { System.out.println("Fila finnes for faen ikke..."); } catch(EOFException e) { JOptionPane.showMessageDialog(null,"END OF FILE!","IO ERROR", JOptionPane.ERROR_MESSAGE); }catch (IOException e) { JOptionPane.showMessageDialog(null,"IO error,noe gikk galt!","IO ERROR", JOptionPane.ERROR_MESSAGE); } } kanskje hjelper deg deg å ta en titt i http://java.sun.com/j2se/1.5.0/docs/api/ Endret 11. mars 2005 av Sletet+adslkfjv
willbend Skrevet 11. mars 2005 Forfatter Skrevet 11. mars 2005 Mener du sånn: import java.io.*; import java.net.*; class dag { public static void main(String args[]) { String minfil="http://www.url.com/mintext.txt"; void hentfil() throws ClassNotFoundException { try { ois = new ObjectInputStream(new FileInputStream(minfil)); while(true) { System.out.println(ois.readObject()); } } catch (FileNotFoundException e) { System.out.println("Fila finnes for faen ikke..."); } catch(EOFException e) { JOptionPane.showMessageDialog(null,"END OF FILE!","IO ERROR", JOptionPane.ERROR_MESSAGE); }catch (IOException e) { JOptionPane.showMessageDialog(null,"IO error,noe gikk galt!","IO ERROR", JOptionPane.ERROR_MESSAGE); } } } }
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå