wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Java Program for file descriptors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Java Program for file descriptors" Watch "Java Program for file descriptors" New topic
Author

Java Program for file descriptors

pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
What I want to do is produce a Java program which does the equivalent of UNIX select() or poll() on a set of file descriptors.Can some help me .or provide any links
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Check out the java.nio.channels package, especially class java.nio.channels.Selector. Note that FileChannel cannot be used with this class since it does not extend SelectableChannel. That's because data from files is regarded as always being available when you ask for it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
Yes FileChannel cannot be used with this class since it does not extend Selectable Channel,so how to over come it any suggestions.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to JavaRanch. Please UseCodeTags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

That's the thing - with FileChannel you don't need to use polling. The data is simply always considered as being available until everything is read.

If you want to read a file that is continually written to, there is currently no support for that in Java.
pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
So any good alternative that you can suggest how it can be done in java.

Well can I write a normal method where it can check all the files in a particular location whether they are redable/writable and then get the list of files that are redable.

Would that be equivalent to same of the unix select () .Please correct me if i am wrong .

@ Rob Prime

Can you explain in detail why with FileChannel you don't need to use polling . and any suggestions.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

pavang kumar wrote:Would that be equivalent to same of the unix select () .Please correct me if i am wrong .

You are wrong. select() has nothing to do with selecting a readable files from a folder, it checks how many of a given set of already open file descriptors (which can also point to sockets or pipes, not just files) have data available.

Can you explain in detail why with FileChannel you don't need to use polling . and any suggestions.

Because FileChannel read operations simply should not block. The contents on the disk are considered to be always available. select() and poll() are to be used with blocking I/O only.
pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
So how should I approach ,well could solve this for me .where i need a select() command similar to unix and can you provide code or any sample program that can make me understand.I will greatly thankful to you.

Please reveiew and help me ...

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Moving to I/O
pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
Well i did not get you exactly. How can that be done uisng I/O .Can you elobrate it so that it can help me as I am novice this .

Can you please provide me an algorithm like thing so that i can move forward.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

I was moving your thread to the I/O and Streams forum, where it is better suited since file descriptors are all about I/O (input/output).
pavang kumar
Greenhorn

Joined: May 27, 2010
Posts: 11
Hi
Any one there .. Please provide a solution..

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Program for file descriptors
 
Similar Threads
FTP
program reagarding reading and writing to a file in java
how to set password to file with java program.?
KB 791
create .mdb file through command