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

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: 23958
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....
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic