Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

How to get file info using File & FileInfo class?

Hi all,

 

How to get file info using File & FileInfo class?

 

plz give me a example with a code snippet.

 

 

Thanks,

Developer
Posts: 211
Registered: ‎04-29-2009
My Device: Not Specified

Re: How to get file info using File & FileInfo class?

Can you please elaborate the question ...? Please specify what info. you need?
Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get file info using File & FileInfo class?

I want file name & file size from File object.

 

I will give my code snippet.

 

File file = (file) fileVector.elementyAt(i);

 

 

I want to get this file's name & size. I read that using FileInfo class, you can get the same. But I am not getting how to use it.

 

Anyone knows the solution for it?

Developer
Posts: 98
Registered: ‎01-06-2009
My Device: Pearl 8110

Re: How to get file info using File & FileInfo class?

Check out the file explorer demo. You should be able to add that easily.
Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get file info using File & FileInfo class?

In FileExplorerDemo, fconn.getName() & fconn.fileSize() is done using FileConnection class.

 

But I want to get the file name & file size using 

FileInfo

 

class. 

 

As from a Vector I am geting the files in File class

File file = (File) fileVector.elementAt(i);

 

 

Now I want to get that file name & file size using FileInfo class using getFileName() & getFileSize().

 

But I am not getting how to do it.

 

Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to get file info using File & FileInfo class?

This what the documentation says about the class File to which FileInfo can be applied:

 

>> Provides low-level access to various file systems. This class provides acces to only the iDEN file system. To access file systems such  as the device store or SDCard use the javax.microedition.io.file classes.

 

So first make sure that this is what you really have ( as file system).

 

As far as using FileInfo, you need to create an  instance of FileInfo, then pass it to File.findFirst() or findNext() : File.findFirst(int, String, FileInfo), and if the return value is true, then use fileInfo.getFileName() etc ...

 

Rab

 

 

Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get file info using File & FileInfo class?

 

Thanks for the reply.

 

I am using a vector for storing some files & after getting a specified file,  I want to get the name of that particular file. Like..

 

File fileFound = (File) fileVector.elementAt(i);

 

FileInfo fileInfo = new FileInfo(); if(File.findFirst(File.FILESYSTEM_PATRIOT , String, fileInfo)) { String fileName = fileInfo.getFileName(); }

Here instead of

 

File.findFirst(File.FILESYSTEM_PATRIOT , String, fileInfo)

I am using

 

File.findFirst(File.FILESYSTEM_PATRIOT , fileInfo)

But the fileName is coming NULL.

 

Here I think I am not getting the correct name of fileFound as I am not passing/referring it anywhere (not referring to FileInfo).

But the FileInfo instance doesnt take any parameter while creating its instance using new.


& what the String argument in File.findFirst(File.FILESYSTEM_PATRIOT , String,  fileInfo)  refers to?

 

How to solve this problem?