• 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

About File class parameters

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there have two directory: subdir and anotherdir.
subdir container one class(AccessFile.class) file and one .java file(AccessFile.java). AccessFile.java content is:

In anotherdir directory alse has a class file(CallIt.class). It's source file:

when I run the CallIt class, I got the following message.

My question:
Why AccessFile class can not find the AccessFile.java(also exist in the same directory)? File class's constructor File(String fileName) how to locate the specified file.
Thanks!
[ November 15, 2002: Message edited by: Mikey Chen ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is in the definition of 'the current directory'
If you are in the root directory '/' and you have two directories 'dir1' and 'dir2'.
dir1 has a class called Class1 in it and it is packaged as dir1.Class1
dir2 also has its own class packaged as dir2.Class2
If you are still in the root directory and type 'java dir1.Class1', it will execute the Class1 file and the current directory will be the root directory.
If you are still in the root directory and type 'java dir2.Class2', it will execute the Class2 file and the current directory will be the root directory.
If you then change directories to the dir1 directory and type 'java dir1.Class1', it will execute the Class1 file but the current directory is now the dir1 directory.
Likewise, if you are still in the dir1 directory and type 'java dir2.Class2', it will execute the Class2 file but the current directory is still the dir1 directory.
This is what you are seeing. The AccessFile.java file is never in the directory you run from so it is never in the default directory.
You would have to a) change directories to the same directory as the AccessFile.java file and execute the program b) call AccessFile.java by its absolute name - ie /subdir/AccessFile.java or c) refer to it by its relative path ie ../subdir/AccessFile.java
Dave
 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David, Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic