• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Working with file and directories..

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23956
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

// 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes it not the part of the file i am printing....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic