• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

File Question

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can anybody help me in explaining the following question from K&B book chapter 6, Q 12:

import java.io.*;
class Directories {
static String [] dirs = {"dir1", "dir2"};
public static void main(String [] args) {
for (String d : dirs) {
// insert code 1 here
File file = new File(path, args[0]);
// insert code 2 here
}
}
}
and that the invocation :java Directories file2.txt
is issued from a directory that has two subdirectories, "dir1" and "dir2", and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt", and the output is "false true", which set(s) of code fragments must be inserted? (Choose all that apply.)

A. String path = d;
System.out.print(file.exists() + " ");

B. String path = d;
System.out.print(file.isFile() + " ");

C. String path = File.separator + d;
System.out.print(file.exists() + " ");

D. String path = File.separator + d;
System.out.print(file.isFile() + " ");

Answer: The ans is (a) and (b), while I tried to run it I am having the following errors:

D:\SST\Java\Directories.java:8: cannot find symbol
symbol : method println(java.lang.String,java.lang.String)
location: class java.io.PrintStream
System.out.println( path, "file1");
^
D:\SST\Java\Directories.java:13: cannot find symbol
symbol : method println(java.lang.String,java.lang.String)
location: class java.io.PrintStream
System.out.println(path,"file2");
^
2 errors

Tool completed with exit code 1

I am not getting why its giving error on println statement.Am I missing some silly thing here.


Thanks in advance
Swapnil
[ June 18, 2006: Message edited by: Swapnil Trivedi ]
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you are trying to call a println() method that takes two String parameters -- and there is no such method.

Henry
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A & B are the correct answers.
You might have some other typo mistake.
print() methods take a single String as argument, so instead of "," use "+"
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic