File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes IO operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "IO operation " Watch "IO operation " New topic
Author

IO operation

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hi,

Is there a way out to perform IO operations from within the JAVA PROGRAM without using the JAVA LIBRARY FUNCTIONS?

If yes a sample code snippet would be of great help.

Thanks in advance,
Saurabh


Success is not doing extraordinary things but doing ordinary things extraordinarily well.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

This reeks of "interview question".
Yes, there are numerous ways. How do you think the JVM does it? It can't very well use java library functions, can it?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Originally posted by Joe Ess:
This reeks of "interview question".
Yes, there are numerous ways. How do you think the JVM does it? It can't very well use java library functions, can it?


Hi,

Thanks a lot for the reply. Yeah JVM also does it internally. One way i think is to make native calls to the C++ API but this will be wierd.This will again mean i am using an API. I want to implement this.So can you please suggest me some options to make this happen.

Thanks in advance,
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Saurabh Agrawal:
Thanks a lot for the reply. Yeah JVM also does it internally. One way i think is to make native calls to the C++ API but this will be wierd.This will again mean i am using an API.


Well, there certainly is now way around using the API of the OS, and using the Java API to call the OS API in some more or less direct way.

I want to implement this.So can you please suggest me some options to make this happen.


Please first explain why do you want to do this. Where is the requirement coming from? That will help us understand what suggestions would be valid.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Originally posted by Ilja Preuss:


Please first explain why do you want to do this. Where is the requirement coming from? That will help us understand what suggestions would be valid.



This was asked to me in one of the interview questions and i wasnt able to justify it,So now i am myself trying to create one program to clear with this idea. Can you please explain me with a sample example.

Thanks in advance,
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

If you see the java source code, for FileInputStream write and write bytes methods,

/**
* Writes the specified byte to this file output stream. Implements
* the <code>write</code> method of <code>OutputStream</code>.
*
* @param b the byte to be written.
* @exception IOException if an I/O error occurs.
*/
public native void write(int b) throws IOException;

/**
* Writes a sub array as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
private native void writeBytes(byte b[], int off, int len) throws IOException;

So its clear.

More inputs are welcome.
Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Originally posted by Srinivas Kalvala:
Hello,

If you see the java source code, for FileInputStream write and write bytes methods,

/**
* Writes the specified byte to this file output stream. Implements
* the <code>write</code> method of <code>OutputStream</code>.
*
* @param b the byte to be written.
* @exception IOException if an I/O error occurs.
*/
public native void write(int b) throws IOException;

/**
* Writes a sub array as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
private native void writeBytes(byte b[], int off, int len) throws IOException;

So its clear.

More inputs are welcome.



How do i get the File object to which i want to write these sequence of bytes. Let me re-iterate that i cant us ethe JAVA API for any functions or classes.

Only thing i can use is the primitive data types and System class to do this thing. Any thoughts ?
Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hi,

I got the context of this problem by using JNI it is possible to achive the same.

I just want to know one thing form the experts of how to create a DLL which can be loaded into the memory?

I dont have VC++ installed on my machine and cant use the same.Are there any free utilities which can be used to create the DLL.

Any help in this context will be highly appreciated.

Thanks in advance,
Saurabh
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

If you are running Windows, you can download and install Cygwin, which includes the Gnu C/C++ compiler (you'll have to indicate during the installation that you want to install gcc).

I don't know all the details of how to make a DLL that's callable using JNI with gcc; see the documentation of Cygwin and gcc for that.

Did you know that there is also a free version of Microsoft Visual C++? It's called Visual C++ 2005 Express Edition. It's probably easier than Cygwin and gcc.
[ September 04, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
 
subject: IO operation