Tags down


can java inputstream read files that are being updated in memory?

By : user3851772
Date : October 15 2020, 11:12 PM
I wish did fix the issue.
lets say we have a excel file that is being updated constantly. Without having to save that excel file, can we read its updated data? – vamsi
code :

Share : facebook icon twitter icon

Java: InputStream too slow to read huge files

By : Rat
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have to read a 53 MB file character by character. When I do it in C++ using ifstream, it is completed in milliseconds but using Java InputStream it takes several minutes. Is it normal for Java to be this slow or am I missing something? , I ran this code with a 183 MB file. It printed "Elapsed 250 ms".
code :
final InputStream in = new BufferedInputStream(new FileInputStream("file.txt"));
final long start = System.currentTimeMillis();
int cnt = 0;
final byte[] buf = new byte[1000];
while (in.read(buf) != -1) cnt++;
System.out.println("Elapsed " + (System.currentTimeMillis() - start) + " ms");

Does a Java InputStream help or hurt memory usage with large files?

By : Sohaib Cheema
Date : March 29 2020, 07:55 AM
I wish this help you I see some posts on StackOverflow that contradict each other, and I would like to get a definite answer. ,
So you are saying that an InputStream would typically help?
code :
  // Efficient use of memory
  try (InputStream is = new FileInputStream(largeFileName);
       BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
      String line;
      while ((line = br.readLine()) != null) {
          // process one line

  // Inefficient use of memory
  try (InputStream is = new FileInputStream(largeFileName);
       BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
      StringBuilder sb = new StringBuilder();
      while ((line = br.readLine()) != null) {
      String everything = sb.toString();
      // process the entire string

  // Very inefficient use of memory
  try (InputStream is = new FileInputStream(largeFileName);
       BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
      String everything = "";
      while ((line = br.readLine()) != null) {
          everything += line + "\n";
      // process the entire string

SAXBuilder().build(InputStream) - does this read entire file into memory?

By : Thibault Lavoisey
Date : March 29 2020, 07:55 AM
With these it helps The DOM parser similarly to the JDom parser loads the whole XML resource in memory to provide you a Document instance allowing to navigate in the elements of the XML.
Some references here :

Why CXF / JAXB read whole InputStream into memory before marshalling to SOAP message

By : Leng Chiva
Date : March 29 2020, 07:55 AM
should help you out You don't need any custom marshallers or change JAXB behaviour to achieve what you need - DataHandler is your friend here.
Answering your first question: JAXB needs to keep all data in memory because it has to resolve references.

Java: How to count read bytes from InputStream without allocating the full memory before

By : Karthik
Date : March 29 2020, 07:55 AM
wish of those help You can use Guava's CountingInputstream or Apache IO's CountingInputStream when you want to know how many bytes have been read.
On the other hand when you want to stop the upload immediatly when reaching some limit then just count while reading chunks of bytes and close the stream when the limit has been exceeded.
Related Posts Related Posts :
  • GWT DatePicker Locale
  • How would you design a twitter like message system, how to design the messaging system?
  • Is there a robust java.util.logging handler implementation of syslog?
  • Aligning messageformat on printing a JTable
  • SXXP0003: Error reported by XML parser: Content is not allowed in prolog
  • ehcache LRU evicting recently used entries
  • java cosine similarity problem
  • Efficient way to implement a client multiple file upload service
  • Regarding Object Comparison
  • How to embed IE in Swing application?
  • Using javax.tools.ToolProvider from a custom classloader?
  • What is the difference between i++ & ++i in a for loop?
  • Match a java main class with regexp
  • Confluence Persistence
  • Is there a way for a SecurityManager in java to selectively grant ReflectPermission("suppressAccessChecks")?
  • Using the camera activity in Android
  • Is communication in java rmi secure?
  • Java - how to make "runnable" JTable?
  • How can I write a Java program to draw a box, an oval, and an arrow?
  • What is the difference between ServletRequest's getRemoteHost() and getServerName()
  • java sparse matrix problem
  • ClassCastException when using HQL
  • how to generate a csv file through java code
  • Netbeans + tomcat on Ubuntu
  • How to connect to a remote MySQL database with Java?
  • System Event Handling using Java
  • How to change Ant script with EMMA code-coverage so it can find runtime coverage data?
  • Java bytecode iconst_0 iadd sequence
  • get the size of a list in a property
  • I want to convert a resultset to a string. I have tried everything but it always gives no data found. Please provide som
  • How can i sort java JTable with an empty Row and force the Empty row always be last?
  • How can I mount network drive in Mac OS X on Java?
  • XStream: How do I map xml mixed attributes and elements to POJOs?
  • begin with java voip
  • java: Preferences API vs. Apache Commons Configuration
  • Howto distinguish Application Quit from System Shutdown
  • How to go about with real GUI development with Java Swing and MVC
  • VB support in Java 6?
  • How to use jar files without package information?
  • how to inherit Constructor from super class to sub class
  • Multidimensional arrays in Java extends which class?
  • Connect to ibm mq with jms . Specify the channel and queue manager
  • Accessing the implicit objects from a JSP EL function
  • Find current heap size with jmap
  • Why doesn't Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||
  • What is the best way to manage configuration data
  • commons fileUpload: specifying an upload directory within Webapplication context
  • ModelAttributes not accessible on jsp
  • Session management between thick client and server?
  • Oracle JDBC intermittent Connection Issue
  • No mapping for LONGVARCHAR in Hibernate 3.2
  • A Packet Blocker Software
  • Anyone using Django in the "Enterprise"
  • Memory leak during repeated lucene query searches?
  • First steps developing in java applet. Directions
  • java efficient de-duplication
  • Converting sequential Java to concurrent java code
  • Java variable number or arguments for a method
  • when developing locally, does it make a difference if the context is '/' or '/appname/'?
  • Problem using JUnit4TestAdapter from eclipse plugin context
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org