import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.io.PrintWriter; class IOexample { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Skriv inn ett tall"); int tall = input.nextInt(); input.nextLine(); // Leser resten av linja, f.eks linjeskift System.out.println("Skriv inn ett tall til"); String tekst2 = input.nextLine(); input.close(); int tall2 = Integer.parseInt(tekst2); System.out.println("IN1: " + tall); System.out.println("IN2: " + tall2); Scanner sc = null; try { sc = new Scanner(new File("tekstfil.txt")); } catch(FileNotFoundException e) { System.out.println(e); System.exit(1); } System.out.println("Kommer ikke hit om en feil oppstar"); ArrayList liste = new ArrayList<>(); while (sc.hasNextLine()) { liste.add(sc.nextLine()); } System.out.println(liste); sc.close(); try { File file = new File("output.txt"); PrintWriter pw = new PrintWriter(file); pw.println("Test"); pw.close(); } catch(FileNotFoundException e) { System.out.println(e); } } }