Skip to content

Instantly share code, notes, and snippets.

@gcr
Created January 24, 2009 06:17
Show Gist options
  • Save gcr/51363 to your computer and use it in GitHub Desktop.
Save gcr/51363 to your computer and use it in GitHub Desktop.
import java.io.*;
/*
** Demonstrates how to set up a pathway between program and disk file
*/
public class FileOutputDemo {
public static void main(String[] args) throws IOException {
// use File
File f1 = new File ("first.dta");
FileOutputStream fileStream = new FileOutputStream (f1);
PrintWriter target = new PrintWriter (fileStream);
target.println ("I really like Java Programming.");
target.println ("It is a powerful OO programming language.");
target.flush();
// use filename
String filename = "second.dta";
fileStream = new FileOutputStream (filename);
target = new PrintWriter (fileStream);
target.println ("This is the second file.”);
target.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment