This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About File class parameters  RSS feed

 
Mikey Chen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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 ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
David, Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!