• Post Reply Bookmark Topic Watch Topic
  • New Topic

Working with file and directories..  RSS feed

 
sonia jaswal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is from K&B pg 440... i have understood the program but i have not understood the output given in the program...
code:

Assume that we already have a subdirectory called existingDir in which resides an existing file existingDirFile.txt, which contains several lines of text. When you run the following code,


File existingDir = new File("existingDir"); // assign a dir
System.out.println(existingDir.isDirectory());

File existingDirFile = new File(
existingDir, "existingDirFile.txt"); // assign a file
System.out.println (existingDirFile.isFile());

FileReader fr = new FileReader(existingDirFile};
BufferedReader br = new BufferedReader(fr); // make a Reader

String s;
while( (s = br.readLine()) != null) // read data
System.out.printIn(s);

br.close();

the following output will be generated:

true
true
existing sub-dir data
line 2 of text
line 3 of text

// here there is no print command for "existing sub-dir data"... then what is it... is it an explanation??? i just want to confirm....

thanks....
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonia jaswal:
...
while( (s = br.readLine()) != null) // read data
System.out.printIn(s);

br.close();

the following output will be generated:

true
true
existing sub-dir data
line 2 of text
line 3 of text


My guess would be that it's the first line in the file: meaning "data in the existing sub-dir". Which is then followed by 2nd and 3rd line of text..

Regards,
Alex
 
Henry Wong
author
Sheriff
Posts: 23291
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// here there is no print command for "existing sub-dir data"... then what is it... is it an explanation??? i just want to confirm....


Are you sure that it isn't part of the file that you are printing out?

Henry
 
sonia jaswal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it not the part of the file i am printing....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!