Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fileiotestapplication;
- import java.io.*;
- import java.io.IOException;
- import java.util.*;
- public class WriterClass {
- @SuppressWarnings("oracle.jdeveloper.java.insufficient-catch-block")
- public WriterClass() {
- super();
- // File f = new File("C:\\Java_Scratch\\someFile.txt");
- int[] content = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,};
- String[] friends = {"bob",};
- File file = new File("/C:/Java_Scratch/someFile.txt");
- // if file doesnt exists, then create it
- try {
- if (!file.exists()) {
- file.createNewFile();
- }
- //BufferedWriter bw = new BufferedWriter(fw);
- for (int i = 0 ; i < content.length; i++)
- {
- //FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
- PrintStream bw = new PrintStream( new FileOutputStream(file, true) );
- System.out.println("testing " + i);
- bw.println( String.valueOf(content[i]) );
- bw.close();
- Thread.sleep(2500);
- }
- System.out.println("Done");
- } catch (IOException ioe) {
- // TODO: Add catch code
- ioe.printStackTrace();
- }
- catch (InterruptedException ioe) {
- // TODO: Add catch code
- ioe.printStackTrace();
- }
- //someIS.println(i);
- System.out.println("This is OK");
- }
- public static void main(String[] args) {
- WriterClass writerClass = new WriterClass();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement