io

Given a Java InputStream, how can I determine the current offset in the stream?

I'd like something like a generic, re-usable getPosition() method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources. Does such a beast exist? If not, c...

How can I record what process or kernel activity is using the disk in GNU/Linux?

On a particular Debian server, iostat (and similar) report an unexpectedly high volume (in bytes) of disk writes going on. I am having trouble working out which process is doing these writes. Two interesting points: Tried turning off system services one at a time to no avail. Disk activity remains fairly constant and unexpectedly hi...

In java, how do you write a java.awt.image.BufferedImage to an 8-bit png file?

I am trying to write out a png file from a java.awt.image.BufferedImage. Everything works fine but the resulting png is a 32-bit file. Is there a way to make the png file be 8-bit? The image is grayscale, but I do need transparency as this is an overlay image. I am using java 6, and I would prefer to return an OutputStream so that I ...

java.net versus java.nio

At what point is it better to switch from java.net to java.nio? .net (not the Microsoft entity) is easier to understand and more familiar, while nio is scalable, and comes with some extra nifty features. Specifically, I need to make a choice for this situation: We have one control center managing hardware at several remote sites (each s...

How do I prevent this System.IO.IOException when copying a file?

When I run the following code to test copying a directory, I get a System.IO.IOException when fileInfo.CopyTo method is being called. The error message is: "The process cannot access the file 'C:\CopyDirectoryTest1\temp.txt' because it is being used by another process." It seems like there's a lock on file1 ("C:\CopyDirectoryTest1\tem...

When to build your own buffer system for I/O (C++)?

I have to deal with very large text files (2 GBs), it is mandatory to read/write them line by line. To write 23 millions of lines using ofstream is really slow so, at the beginning, I tried to speed up the process writing large chunks of lines in a memory buffer (for example 256 MB or 512 MB) and then write the buffer into the file. This...

Which is faster for a small amount of information, java file i/o or derby?

I'm writing a small agent in java that will play a game against other agents. I want to keep a small amount of state (probably approx. 1kb at most) around between runs of the program so that I can try to tweak the performance of the agent based upon past successes. Essentially, I will be reading a small amount of data at the beginning of...

How to decompress a gzipped data in a byte array?

I have a class which has a method that is receiving an object as a parameter. This method is invoked via RMI. public RMIClass extends Serializable { public RMIMethod(MyFile file){ // do stuff } } MyFile has a property called "body", which is a byte array. public final class MyFile implements Serializable { priv...

AccessControlException when attempting to delete a file

We have a java web service application that uses log4j to do logging. An exception gets thrown when log4j tries to delete its rolling log files Exception:java.security.AccessControlException: access denied (java.io.FilePermission /var/opt/SUNWappserver/domains/domain1/ applications/j2ee-modules/ourwebservice/WEB-INF/logs/IMWrapper.log....

Java: CharBuffer vs. char[]

Is there any reason to prefer a CharBuffer to a char[] in the following: CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append( buf.flip() ); buf.clear(); } vs. char[] buf = new char[DEFAULT_BUFFER_SIZE]; int n; while( (n = in.read(buf)) >= 0 ) { out.write( buf, 0, n ); } (where in...

What's the best way of reading a sprite sheet in Java?

I'm writing a basic sprite engine for my own amusement and to get better aquainted with Java's 2d API. Currently I am making use of large numbers of separate .png files with transparent backgrounds to represent the various sprites and different frames of animation that I need. Most 'real world' game development projects seem to make use ...

Get the startup path in a vb.net console exe

How do get the startup path ( system.windows.forms.application.StartupPath ) of my exe without adding a reference to system.windows.forms? ...

Java: Reading integers from a file into an array.

File fil = new File("Tall.txt"); FileReader inputFil = new FileReader(fil); BufferedReader in = new BufferedReader(inputFil); int [] tall = new int [100]; String s =in.readLine(); while(s!=null) { int i = 0; tall[i] = Integer.parseInt(s); //this is line 19 System.out.println(tall[i]); s = in.readLine(); } in.close(); ...

In Java how do a read/convert an InputStream in to a string?

If you have java.io.InputStream object how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert this to a String (for example, so I can write the contents of the stream to a log file). What is the easiest way to take the InputStream and convert it to a Strin...

What's the best way to open and read a file in Perl?

Edit on 11/26 - Please note - I am not looking for the "right" way to open/read a file, or the way I should open/read a file every single time. I was just interested to find out what way most people use, and maybe learn a few new methods at the same time :) A very common block of code in my perl programs is opening a file and reading o...

How to create a Java String from the contents of a file

I've been using this idiom for some time now. And it seems to be the most wide spread at least in the sites I've visited. Does anyone have a better/different way to read a file into a string in Java. Thanks private String readFile( String file ) throws IOException { BufferedReader reader = new BufferedReader( new FileReader (fil...

Cannot delete directory with Directory.Delete(path, true)

I'm using .NET 3.5, trying to recursively delete a directory using: Directory.Delete(myPath, true); My understanding is that this should throw if files are in use or there is a permissions problem, but otherwise it should delete the directory and all of its contents. However, I occasionally get this: System.IO.IOException: The direc...

Best pretty-printing library for Java?

What is the single best pretty-printing library for Java? I mean a library for printing formatted output with indentation, break hints, etc., not a library for beautifying/re-formatting Java code itself. Ideally, the library would "play nice" with System.out.println and friends. For an idea of what I'm looking for, see OCaml's Format mo...

Java File I/O Performance Decreases Over Time

I'm trying to perform a once-through read of a large file (~4GB) using Java 5.0 x64 (on Windows XP). Initially the file read rate is very fast, but gradually the throughput slows down substantially, and my machine seems very unresponsive as time goes on. I've used ProcessExplorer to monitor the File I/O statistics, and it looks like th...

Good F# Asynchronous IO Sample

Hi, Where can I find a good sample of Asynchronous IO on files with thread hooping? Thanks ...