From caa45609f65c184f39f5ab91dabd783b70ef8e1e Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Sat, 4 Apr 2026 19:32:12 -0500 Subject: [PATCH] fileio buffered for fast --- templates/java/FileIOBuffered.java | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 templates/java/FileIOBuffered.java diff --git a/templates/java/FileIOBuffered.java b/templates/java/FileIOBuffered.java new file mode 100644 index 0000000..241955c --- /dev/null +++ b/templates/java/FileIOBuffered.java @@ -0,0 +1,75 @@ +import java.util.*; +import java.io.*; +import java.math.*; + +public class FileIOBuffered { + + static final String INPUT_FILE = "problem.in"; // ← change to problem name + static final String OUTPUT_FILE = "problem.out"; // ← change to problem name + + static BufferedReader br; + static PrintWriter pw; + static StringTokenizer st; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new FileReader(INPUT_FILE)); + pw = new PrintWriter(new BufferedWriter(new FileWriter(OUTPUT_FILE))); + + // Write code here + int t = nextInt(); + print(t); + + pw.flush(); + pw.close(); + } + + // Helper Functions + + static String next() throws IOException { + while (st == null || !st.hasMoreTokens()) + st = new StringTokenizer(br.readLine()); + return st.nextToken(); + } + + static int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + static long nextLong() throws IOException { + return Long.parseLong(next()); + } + + static double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + static String nextLine() throws IOException { + return br.readLine(); + } + + static int[] readIntArray(int n) throws IOException { + int[] a = new int[n]; + for (int i = 0; i < n; i++) + a[i] = nextInt(); + return a; + } + + static long[] readLongArray(int n) throws IOException { + long[] a = new long[n]; + for (int i = 0; i < n; i++) + a[i] = nextLong(); + return a; + } + + static void println(Object o) { + pw.println(o); + } + + static void print(Object o) { + pw.print(o); + } + + static void printf(String fmt, Object... args) { + pw.printf(fmt, args); + } +}