Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IO operation

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic