Is there a java library / package analogous to <stdio.h>?

Posted by Roboprog on Stack Overflow See other posts from Stack Overflow or by Roboprog
Published on 2010-05-13T01:44:09Z Indexed on 2010/05/13 1:54 UTC
Read the original article Hit count: 347

Filed under:
|
|

I have been doing Java on and off for about 14 years, and almost nothing else the last 6 years or so.

I really hate the java.io package -- its legion of subclasses and adapters. I do like exceptions, rather than having to always poll "errno" and the like, but I could surely live without declared exceptions.

Is there anything that functions like the Unix/ANSI stdio.h routines in C?

I know we will never be rid of java.io and its conventions until java itself is retired, as they have metastasized throughout the many frameworks that have accreted to java. That said, I would like something that works kind of like this (let's call it package javax.stdio):

Have a main utility class, perhaps FileStar, that can read and write files (or pipes), either text or binary, either sequentially or random access, with constructors that mimic fopen() and popen().

This class should have a load of useful methods that do things like fread(), fwrite(), fgets(), fputs(), fseek(), and whatever else (fprintf()?). Methods that are incompatible with the open/construct mode simply throw up (just like some of the collections classes/methods do when restricted).

Then, have a bunch of interfaces that suggest how you intend to use the stream once you have created it: Sequential, RandomAccess, ReadOnly, WriteOnly, Text, Binary, plus combinations of these that make sense. Perhaps even have methods to return the appropriate type-cast (interface), throwing up if you have asked for something incompatible.

For extra flavor, skip the declared exceptions -- e.g. - javax.stdio.IOException extends RuntimeException.

Is there an open source project like this floating around?

© Stack Overflow or respective owner

Related posts about java

Related posts about java.io