Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Working with file and directories..  RSS feed

 
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....
 
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
 
author
Sheriff
Posts: 23571
138
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....
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!