• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creation of Font object for directory in current directory  RSS feed

 
Sameer Shinde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
How to create a File object for a directory contained in the current directory?
We usually place the resources like fonts, gif images in a RSC direcory
in the current directory.
I dont want to include full path name of the folder as a parameter.
I tried the following but it won't work:

File file= new File("./RSC");

File file= new File("RSC");

File file= new File(".\RSC");

Please give OS independant representation for the same.

-Sameer
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
545
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shekaru Koyana:
File file= new File("RSC");

Sameer,
Welcome to JavaRanch!

The above creates a file handle (like a pointer) to your file. At this point the file may exist (if someone created it already) or not exist (if it is a new file.)

To actually create the file, you need to call file.createNewFile(). Alternatively, you can create a file by writing to it.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shekaru Koyana:
...I tried the following but it won't work: ...

What do you mean "it won't work"? How does the behavior of your program differ from what you expect? I don't understand what you are trying to do, so if you can please explain more clearly, we'll try to help more. If you are getting error messages, please post them EXACTLY AS THEY APPEAR. We will be more than happy to help you, but we need more details as to what is going on.

Keep Coding!

Layne
 
Sameer Shinde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
My project folder is
c:\jdk1.5.0\bin\nb

Under this folder there is another folder named RSC.
c:\jdk1.5.0\bin\nb\rsc

This RSC folder contains resources files i.e. fonts files.
I want to create a Font object from each of the file and then put the object in a vector.
For this purpose I need to create a File object for the folder RSC.
My current working directory(.) is "nb".
Then how do I refer to this folder (RSC) in the declaration of File class.

Currently I am referring to it using the full path as follows:

File file = new File("C:\\jdk1.5.0\\bin\\nb\\rsc");
File[] fileList = file.listFiles();

Vector v=new Vector();

for (int i = 0; i < fileList.length; i++) {
Font f;
FileInputStream fis = new FileInputStream(fileList[i]);
f = Font.createFont(Font.TRUETYPE_FONT, fis);
v.add(i, f);
}


Can you suggest how to declare a File object so that it will be path independant and will

refer to . (current directory).
THE PATH MUST BE RELATIVE.


-Sameer



Originally posted by Layne Lund:

What do you mean "it won't work"? How does the behavior of your program differ from what you expect? I don't understand what you are trying to do, so if you can please explain more clearly, we'll try to help more. If you are getting error messages, please post them EXACTLY AS THEY APPEAR. We will be more than happy to help you, but we need more details as to what is going on.

Keep Coding!

Layne
 
Sameer Shinde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
My project folder is
c:\jdk1.5.0\bin\nb

Under this folder there is another folder named RSC.
c:\jdk1.5.0\bin\nb\rsc

This RSC folder contains resources files i.e. fonts files.
I want to create a Font object from each of the file and then put the object in a vector.
For this purpose I need to create a File object for the folder RSC.
My current working directory(.) is "nb".
Then how do I refer to this folder (RSC) in the declaration of File class.

Currently I am referring to it using the full path as follows:

File file = new File("C:\\jdk1.5.0\\bin\\nb\\rsc");
File[] fileList = file.listFiles();

Vector v=new Vector();

for (int i = 0; i < fileList.length; i++) {
Font f;
FileInputStream fis = new FileInputStream(fileList[i]);
f = Font.createFont(Font.TRUETYPE_FONT, fis);
v.add(i, f);
}


Can you suggest how to declare a File object so that it will be path independant and will

refer to . (current directory).
THE PATH MUST BE RELATIVE.


-Sameer




Originally posted by Layne Lund:

What do you mean "it won't work"? How does the behavior of your program differ from what you expect? I don't understand what you are trying to do, so if you can please explain more clearly, we'll try to help more. If you are getting error messages, please post them EXACTLY AS THEY APPEAR. We will be more than happy to help you, but we need more details as to what is going on.

Keep Coding!

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!