File io in java

import java.io.*; import java.util.*; public class FileProgram { public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("D:\\k\\hello.txt"); PrintStream fout = new PrintStream(fos); fout.printf("Lotto : %d %d %d", 1, 2, 3); fout.close(); fos.close(); FileInputStream fis = new FileInputStream("D:\\k\\hello.txt"); Scanner fscan = new Scanner(fis); fscan.next(); int n1 = fscan.nextInt(); int n2 = fscan.nextInt(); int n3 = fscan.nextInt(); System.out.printf("%d %d %d", n1, n2, n3); fscan.close(); fis.close(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.