Share on Google+Share on Google+

SCJP Module-10 Question-5

This sample code will test your understanding of opening a file and writing data onto the file.

Given a sample code:

1    import*;

2    class Test3 {
3    public static void main(String[] args) {
4    try {
5    // Place code here.
6    w.write("hello user");
7    w.close();
8    } catch (IOException e) {
9    System.out.println(e);

What code can be placed at line no 5 for creating a file and writing to it ? Choose the correct options?

(A) FileWriter w = new FileWriter("user.txt");
(B) File w = new File("user.txt");




Posted on: July 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.