Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created June 13, 2022 13:46
Show Gist options
  • Save uncoded-ro/410a004a16bc73ceacdca5fc7bd989f1 to your computer and use it in GitHub Desktop.
Save uncoded-ro/410a004a16bc73ceacdca5fc7bd989f1 to your computer and use it in GitHub Desktop.
package ro.virtualcampus.read;
import java.io.*;
public class ReadToFile {
public static void main(String[] args) throws IOException {
BufferedReader fin = null;
PrintWriter fout = null;
try {
fin = new BufferedReader(new InputStreamReader(System.in));
fout = new PrintWriter(new FileWriter("out.txt"));
String buffer;
while ((buffer = fin.readLine()).indexOf(".") != 0) {
fout.println(buffer);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fin != null)
fin.close();
if (fout != null)
fout.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment