performance « Development « Java I/O Q&A





1. Java File Cursor    stackoverflow.com

Is there some library for using some sort of cursor over a file? I have to read big files, but can't afford to read them all at once into memory. I'm ...

2. Is there a workaround for Java's poor performance on walking huge directories?    stackoverflow.com

I am trying to process files one at a time that are stored over a network. Reading the files is fast due to buffering is not the issue. The ...

3. Java Object Serialization Performance tips    stackoverflow.com

I must serialize a huge tree of objects (7,000) into disk. Originally we kept this tree in a database with Kodo, but it would make thousands upon thousands of Queries ...

4. What is the fastest way to read a large number of small files into memory?    stackoverflow.com

I need to read ~50 files on every server start and place each text file's representation into memory. Each text file will have its own string (which is the best type ...

5. Counting the number of files in a directory using Java    stackoverflow.com

How do I count the number of files in a directory using Java ? For simplicity, lets assume that the directory doesn't have any sub-directories. I know the standard method of :

new ...

6. Most efficient idiom to read one integer only from a file?    stackoverflow.com

In trying to resolve Facebook's Puzzle "Hoppity Hop", http://www.facebook.com/careers/puzzles.php?puzzle_id=7, I'm reading one integer only from a file. I'm wondering if this is the most efficient mechanism to do this?

private ...

7. How to retrieve a list of directories QUICKLY in Java?    stackoverflow.com

Suppose a very simple program that lists out all the subdirectories name of a given directory. Sound simple enough? Except the only way to list all subdirectories in Java is to ...

8. Why does reading a file into memory takes 4x the memory in Java?    stackoverflow.com

I have the following code which reads in the follow file, append a \r\n to the end of each line and puts the result in a string buffer:

public InputStream getInputStream() throws ...

9. Poor performance by overriding Java class?    stackoverflow.com

I have the following class subclass of FilterInputStream with only one method overrided. However the performance of this class is so poor. It performs at 1/10 the speed of its superclass. ...





10. What are the issues with non-static inner classes and serialization in Java    stackoverflow.com

This morning my boss and I had a long and ultimately fruitless discussion about this, in the context of trying to diagnose performance problems with a web application. We didn't ...

11. File copying in Java    stackoverflow.com

What is a better option (in terms of performance): copying a file using fileinputstream and fileoutputstream or running a OS specific command copy command from Java?

12. Java does not have a listDirectories/listFiles method, any native library?    stackoverflow.com

Possible Duplicate:
How to retrieve a list of directories QUICKLY in Java?
Java does not have a listDirectories/listFiles method, in order to find out your ...

13. Read large amount of data from file in Java    stackoverflow.com

I've got text file that contains 1 000 002 numbers in following formation:

123 456
1 2 3 4 5 6 .... 999999 100000
Now I need to read that data and allocate it ...

14. How to pass a file (read from Java) most effectively to a native method?    stackoverflow.com

I have approx. 30000 files (1MB each) which I want to put into a native method, which requires just an byte array and the size of it as arguments. I looked through ...

15. Is Java serialization a tool to shrink the memory footprint?    stackoverflow.com

does serialization in Java always have to shrink the memory that is used to hold an object structure? Or is it likely that serialization will have higher costs? In other words: Is ...

16. read files from directory and filter files from Java    stackoverflow.com

The following codes goes through all directories and sub-directories and outputs just .java files;

import java.io.File;


public class DirectoryReader {
    private static String extension = "none";
    private ...





17. java file move high performance    stackoverflow.com

I am writing a media transcoding server in which I would need to move files in the filesystem and till now I am in the dilemma of whether using java renameTo ...

18. is using import some.directory.* worse for performance?    stackoverflow.com

What is better for performance using

import some.directory.*; 
or
 import some.directory.classNeeded;
Or does this not make any change on performance as the compiler discounts libraries that aren't used with in the ...

19. Performance difference between Serializable and Externalizable (Java)    stackoverflow.com

I am working in a highly distributed environment. A lot of network access and a lot of db access. I have some classes that are send over and over the network , ...

20. Java NIO vs DotNet IO Performance    stackoverflow.com

Does anyone know what the performance difference is between Java NIO vs DotNet IO performance. Reading this question, it seems that standard Java-IO and DotNet-IO have very similar IO performance. What is ...

21. Most efficient way to read files in Java?    stackoverflow.com

As most other people, I deal with file I/O a lot and I wanted to make sure that I wasn't losing time on reading the file. I currently know of FileReader() ...

22. Speeding up java deep copy operations    stackoverflow.com

We have implemented a general purpose deep copy mechanism using serialization.

import java.io.*;

public class CopyUtil {

    public static Object clone(Object source) {
        ...

23. Java File access - Performance considerations    stackoverflow.com

All, Considering my earlier query Stackoverflow-Post, here is what I am currently doing. This is a kind of flowchart: 1 > Add record to file:
a. ...

24. NTFS directory has 100K entries. How much performance boost if spread over 100 subdirectories?    stackoverflow.com

Context We have a homegrown filesystem-backed caching library. We currently have performance problems with one installation due to large number of entries (e.g. up to 100,000). The problem: we store all fs ...

25. Speeding up OpenNLP's POSTagging when using it for several texts    stackoverflow.com

I'm currently working on a keyphrase extraction tool, which should provide tag suggestions for texts or documents on a website. As I am following the method proposed in this paper:

26. Question on Java IO Performance tuning    stackoverflow.com

I am trying to optimize a web based application that does a lot of writing to the stream. The code is something like this ---

 StringWriter stringWriter = new StringWriter(1024);
 PrintWriter printWriter ...

27. what's the fastest way to scan a very large file in java?    stackoverflow.com

Imagine I have a very large text file. Performance really matters. All I want to do is to scan it to look for a certain string. Maybe I want to count how many ...

28. What would be "faster" when dealing with input and output?    stackoverflow.com

A simple program asking for user input could use datainputstream or scanner. Which would be faster? Datainputstream is binary so it may be faster? Is it in opinion? I'm just curious ...

29. temp files in memory in java program    stackoverflow.com

Is there a way to force the temporary files created in a java program in memory? Since I use several large xml file, I would have advantages in this way? Should ...

30. Netty performance    stackoverflow.com

Is there any real difference to the performance when you use Netty and if you don't use it in an application with tens of thousand of connections?

31. Advantages of Java NIO in blocking mode versus traditional I/O?    stackoverflow.com

I have pretty much already decided not to use asynchronous, non-blocking Java NIO. The complexity versus benefit is very questionable in general, and I think it's not worth it in this ...

32. Does compression increase performance?    stackoverflow.com

I'm using java and have many pictures to load from the hard drive. Generally, is it faster to use highly compressed pictures (that probably take long to decompress) or not compressed pictures ...

33. Why do I get java.lang.OutOfMemoryError given the size of my file?    stackoverflow.com

I'm parsing a 328kb text file and storing the content in a java List. This is the command line (I'm supposed to use 1GB ram given the parameters).

java -Xms128m -Xmx1024m -cp .:jars/* ...

34. Java: Efficient way to scan a folder for a particular file    stackoverflow.com

I am contacting an external services with my Java app. The flow is as follow: ->I generate an XML file, and put it in an folder, then the service processes the ...

35. Java Ant Performance when deleting directory    stackoverflow.com

Hello fellow stackoverflowers, Most Ant build files I've seen online involve a "clean" target that always removes a directory using deltree and recreates that directory, where all the binaries will be outputted ...

36. Faster way to read file    stackoverflow.com

I'm working on a program that has about 400 input files and about 40 output files. It's simple: it reads each input file and it generates a new file with but much ...

37. Which xml serialization library is performance oriented?    stackoverflow.com

What is the best XML serialization library for Java if performance is the deciding factor? Salient Points of application

  • Rest Based API.
  • Tomcat Servlet Container
  • Requires Java Object to XML Serialization
  • No requirement for Deserialization or ...

38. java: need to increase performance of checksum calculation    stackoverflow.com

I'm using the following function to calculate checksums on files:

public static void generateChecksums(String strInputFile, String strCSVFile) {
    ArrayList<String[]> outputList = new ArrayList<String[]>();
    try {
  ...

39. What would be the fastest way to read integers from a file in Java?    stackoverflow.com

I have a file of integers arranged like this:

1 2 3 55 22 11 (and so on)
And I want to read in these numbers as fast as possible to lessen the ...

40. Storing lots of small files: archive vs. filesystem    stackoverflow.com

I am creating an application that requires a lot of image thumbnails (~3000, 5-25KB). Because speed is essential I plan on loading these images into memory when the application starts. At ...

41. OutOfMemoryError - can I dump data into file instead of memory?    stackoverflow.com

I'm using an API that provides a method like remoteConnection.getObjects() to get a list of objects from a remote server. The list is sometimes huge and causes a Java heap space ...

42. Will using longs instead of ints benefit in 64bit java    stackoverflow.com

In a 64 bit VM, will using longs instead of ints do any better in terms of performance given that longs are 64 bits in java and hence pulling and processing ...

43. Optimising file download    stackoverflow.com

So I've got the following method for downloading files from Amazon S3 and for now it is working but I anticipated that in the future I'll have to deal with considerably ...

44. Faster output via standard out in Java?    stackoverflow.com

In an online judge programming contest problem I am required to output up to 50,000 lines in under 1 second via standard out (in addition to reading in up to 200,000 ...

45. Sensible buffer size when downloading files in Java    stackoverflow.com

What is the sensible buffer size to use when transferring (irrespective of UP/DOWN) large files (3-4 gigs) with Java?

byte buf[] = new byte[1024]
or
byte buf[] = new byte[5 * 1024 * ...

46. Apache Camel File Output Component Performance slow - Java    stackoverflow.com

I'm using Camel to write a number of strings (100,000s) to set of text files. The below code shows my Camel route:

from("seda:fileOutputMatchedMsgClose?concurrentConsumers=44")
.to("file:MATCHED_CLOSE?fileExist=Append")
.end();
So basically what's happening is I have a producer bean which ...

47. NIO Performance Improvement compared to traditional IO in Java    stackoverflow.com

I have seen many articles/blogs saying that Java NIO is a better solution compared to traditional Java IO. But today one of my co-worker showed me this blog http://mailinator.blogspot.com/2008/02/kill-myth-please-nio-is-not-faster-than.html. I ...

48. How can I measure file access performance (and volume) of a (Java) application    stackoverflow.com

Given an application, how can I measure

  • the amount of data read and written by that application?
  • the time spent reading/writing to disk?
The specific application is Java-based (JBoss), and multi-threaded, and running ...

49. How can I read a certain amount of Bytes into a Buffer?    stackoverflow.com

The following problem: I have a large textfile with each line containing 13 bytes. I do not want to read the file line by line in the common way using InputStream. ...

50. Performance with File Output    coderanch.com

Hi - I was wondering if anyone had any comments on performance issues related to writing data to a file. Currenctly, I'm performing the task like this: File f = new File("test.txt"); File Writer fs = new FileWriter(f); fw.write("This is a test"); I would like to hear comments about whether or not this is good from a perfomance standpoint or is ...

51. Object serialization performance    coderanch.com

An interesting question came up today: all other things being equal, is there a performance difference between writing a serialized object to a file and writing that object's data to a file? The object in question is a StringBuffer. I would tend to think that just writing the data to the file would be quicker, but that's a guess. Any thoughts? ...

52. File size and Performance    coderanch.com

It depends on your program. Just opening a file (by creating a FileInputStream for example) does not take up a huge amount of memory and the memory usage is not dependent on how large the file is. If you write a program that loads the whole contents of the file into memory, then yes, your program will need a lot of ...

53. StringBuffer performance    coderanch.com

I have a large text processing application, and for once I am worried about java performance. Can someone help me evaluate these two approaches to meet the principle: Reuse; do not destroy and re construct in a loop. Which scenario improves performance the most, and why? Here is a terse example: StringBuffer sb = new StringBuffer(); //... While (loopIsNotDone) { //... ...

54. Testing serialization performance    coderanch.com

I got this code from an article on javaworld. The original author used it to test deep-copying via serialization. Another article used the code to test serialization performance (http://www.javaworld.com/jw-09-2001/jw-0907-rmi.html ; the first bullet under Resources) Since I don't know too much about serialization, does this code look like a good performance tester for serialization? I'm considering making some of my classes ...

55. Setting serialVerionUID for performance    coderanch.com

57. IO Performance    coderanch.com

Dear Sir, I am using BufferedOutptStream class to write byte array to a file. Is there any other way to write to the file in a more effecient way in java . i have my own class called VFSIOService which has the methods addFile and copyFile which are responsible for writing and copying. This class is called by a stateless session ...

58. nio performance issue    coderanch.com

Dear Sir, I am doing I/O in my project for which I have decided to choose either nio or java.io for file writing and reading . I thought to choose nio because it uses direct memory and gives good performance . I was comparing nio with java.io for writing and reading a file size of 3mb . I was calculating the ...

59. NIO and performance question    coderanch.com

package org.jemos.nio; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class RemainingTest { public static void main(String[] args) { new RemainingTest().doTest(); } private void doTest(){ ByteBuffer buf = ByteBuffer.allocate(5).order(ByteOrder.BIG_ENDIAN); buf.put((byte)'H').put((byte)'e').put((byte)'l').put((byte)'l').put((byte)'o'); buf.flip(); printByteBuffer(buf); printStats(buf); } private void printStats(Buffer buf){ System.out.println("Position:\t" + buf.position()); System.out.println("Limit:\t" + buf.limit()); } private void printByteBuffer(ByteBuffer buf){ while(buf.hasRemaining()){ System.out.print((char)buf.get()); } System.out.println(""); } }

60. SequenceInputStream performance    coderanch.com

I'm using a SequenceInputStream to read multiple files and merge them together into one file. This is way slow. I'm guessing due to buffering. How do I properly buffer with a SequenceInputStream. My code is below. Note that I'm buffering output, but not input. I tried using s.read(byte[] b, int off, int len) but my output was wacked, I apparantly did ...

61. Any Performance Optimization Tips for using NIO    coderanch.com

In most cases it's as Joe says. On big exception is - if you want to copy bytes to or from a file - use FileChannel's transferFrom() or transferTo() methods. They are faster (typically) and easier to use than doing the same thing with streams. Which is unusual - typically the NIO stuff is harder to use, and only sometimes is ...

62. File Input performance    coderanch.com

I have a few massive text files I have to sort through and move. I'm having a seperate thread for each text file use a FileInputStream and several FileWriters to bring the data in, check where it belongs, and then put it there. Is this the best way to handle this? It seems like its rathers slow (old visual basic version ...

63. Performance Problem?    coderanch.com

I have web application. I have a file which has 2 million records, each record is of one line however size is variable but max 32 characters. I display records on page (1,000 records a page). Here user can add record as well as modify/edit record as all 1000 records shown on page can be modified. Also user may delete record ...

64. How to measure performance improvement over unbuffered file I/O?    coderanch.com

I've a piece of code that does quite a lot of file I/O. The application is running on Solaris. Gotten a lot of high system CPU utilization and read somewhere that this is due to unbuffered I/Os. So I rewrote the code and uses buffers for it. How do I quantitatively shows that the buffered codes is better than the unbuffered ...

65. Permission control: File Upload and Download - Want to improve performance    coderanch.com

Greetings, I have a web app (running in Tomcat) which allows user to login and upload files. The uploaded files are saved to /WEB-INF/resources/user_name/filename The uploaded files should only be available to the uploader. So, when the user login and try to download the files they uploaded, I use a URL pattern /data/user_name/filename and map this pattern to a servlet. When ...

66. Best performance: read a huge file    coderanch.com

I am thinking a performance issue. If I have a huge txt file (say, 4GB), like name1,address1,date1......\n name2,address2,date2......\n ..... I need to read it, parse it, make some conversion(i.e, change data format) and then save it to database. Which way we could get the best performance ? what collection type (vector, arraylist?) we need to use ? So far, one thing ...

67. best performance / practices for read and parse files ?    coderanch.com

It's hard to say in advance if there would be any benefit in making this a multi-threaded program. I'd just start with writing a small and simple single-threaded program that does a batch update for every N records (and you'd have to try out which value of N works best). If the performance is not good enough, try more complicated things ...

68. object-encapsulation vs performance / class-file-size    coderanch.com

I have a object and I am not sure to place a (long) method within this object to set some properties which only belongs to this object-instance. What if I retrieve (for example, 100000) object-instances. Would it be not better, to place this (long) method out of that object-instance in a separate class (for example, a business-class) and invoke it from ...

69. IO and Performance    java-forums.org

Hi Guys, I am facing a performance related issue in my code. Below is the code snippet. public static Map chunkFile(String fileName, String fromFileLocation, long interval, long parentId, String toFileLocation) throws Exception { String thisLine; String thisLine1 = GenericConstants.EMPTY_STRING; long countRecord = 0; BufferedReader brReader = null; ChunkAndPriorityService chunkAndPriorityService = new ChunkAndPriorityServiceImpl(); long id = 0; Map childFileMap = ...

70. performance in scanning and manage many files. Can I improve?    forums.oracle.com

Yes, I know is odd code; but the idea was if you expert see something odd that can eat performance. For example I was wondering if I could work around method "read" and on the scanner part. I don't know fine ho exception work, so I'll read about it, thanks, EDIT: I don't understand the part of exception: could you briefly ...

71. looking for performance boost to java.nio.charset.encode(String) method    forums.oracle.com

So if it was reduced to zero time your application would now be 1.00/0.96 = 1.0416666666666666666666666666667 times as fast. The rule of thumb in software engineering is that if you can't make it 10 times as fast don't bother. The hardware will make it twice as fast in 18 months' time anyway. Stressing about an improvement factor of 1.0416 is a ...

72. bad file reading performance on Mysaify JVM    forums.oracle.com

73. File processing : how could C# have better performance than Java ?    forums.oracle.com

Microbenchmarks are notoriously problematic in modern VM-based systems, because they can get useless results, due to just-in-time compilation. Java for example uses HotSpot, which will usually interpet your Java code and track which code gets executed often. If it finds such a "hot spot" (code which is executed repeatedly), then it will produce an optimized, native-code version that is executed from ...

74. bad performance of File.renameTo()    forums.oracle.com

i use Fil.renameTo()methode to move 100k files from a folder to another.Both the folder are in the same mount. Os:solaris 10 JDK:1.4.2 When have 20 concurreny users , the performance is bad. this is the time used to move:(unit ms) 07/24 14:02:01 596=== 07/07/24 14:02:01 3423=== 07/07/24 14:02:02 3567=== 07/07/24 14:02:02 3851=== 07/07/24 14:02:02 3256=== 07/07/24 14:02:02 3646=== 07/07/24 14:02:02 3048=== ...

75. Copy File - performance / interruption    forums.oracle.com

When I use buffersize = (64 * 1024 * 1024) - (32 * 1024); - advantage: it is ~20% faster - disadvatange: it takes up 5-10 seconds until it stops, when user hit the stop button I tried with buffersize 16384, which is 2^14, so it is the happy medium. It is fast enough with the current approach I am using, ...

76. File I/O - Performance design    forums.oracle.com

I would like a design solution on File I/O I have a nighlty batch process, which reads records from a flat file, validates the records, creates error for records if any and update the file status in database. The text file can have 500,000 or more records. Design I have thought of: 1) Iterate through records using BufferedReader, create a POJO, ...