473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

which api/method to use for concatenating multiple large files using least RAM?

Hi

I have multiple files (between 50-100) that basically contain simple text. Each file ranges in size from few MB to 50MB.

I have to concatenate all these files to produce one single file that contains the content of all the files-- and I have to do this in a machine that has quite less RAM-- I can use max 512MB RAM for the JVM.

How do I do this? Which API/method do I use to accomplish concatenation of multiple files while using least values?
Jan 4 '13 #1
2 2286
try this
Expand|Select|Wrap|Line Numbers
  1. public void concatFile() {
  2.         PrintWriter pw = new PrintWriter(new FileOutputStream("C:/temp/out/out.txt"));
  3.         File file = new File("C:/temp/");
  4.         File[] files = file.listFiles();
  5.         for (int i = 0; i < files.length; i++) {
  6.                 BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
  7.                 String line = br.readLine();
  8.                 while (line != null) {
  9.                         pw.println(line);
  10.                         line = br.readLine();
  11.                 }
  12.                 br.close();
  13.         }
  14.         pw.close();
  15. }
  16.  
simply read line by line, each file
Jan 4 '13 #2
Anas Mosaad
185 128KB
You may leverage the operating system capabilities to implement this task. Windows copy command can do this utlra fast.
For example, if you have 4 files to concatenate (T1.txt... T4.txt) into one file T5.txt, the following command can make it for you.

Expand|Select|Wrap|Line Numbers
  1. copy /B T1.txt+T2.txt+T3.txt+T4.txt T5.txt
Linux version would be:
Expand|Select|Wrap|Line Numbers
  1. cat T1.txt T2.txt T3.txt T4.txt > T5.txt
I'm expecting you to know how to execute OS commands from Java.

Good luck.
Jan 5 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jen | last post by:
Trying to take one table in access and split it into multiple excel files(using an excel template); and then email based on email addresses in Table2; Of course, I would like to do all of this...
4
by: Randy | last post by:
I'm writing an application where the user interface has many tabs, and sets of tabs within each tab (customer requirement). Each subtab has a great number of it's own controls and functions. Rather...
1
by: Wallace | last post by:
Hi all, I have a problem on validating a xml fragment using a single namespace schema which spread across multiple schema files using include in the master schema file. No matter how I change...
6
by: Ramesh | last post by:
Hi, We are receiving an error 'The operation has timed out' when our ASP.NET application on Web Server stores large files 10MB+ on the App Server using HTTP PUT. This is a Server to Server...
1
by: AWHK | last post by:
Hi, I have a customer which want to upload LARGE files via a web-service and stream it into a database while it is uploading. I don't want to go out of my way and develop a large HTTP App....
1
by: rajarameshvarma | last post by:
Hi.. I am facing problems with file uploading in asp.net.my filea are nearly 40 MB size. I set the MaxRequestLength property to match. Files are getting uploaded but it is taking so much time. I...
1
by: =?Utf-8?B?UHJhc2FkIFBhdGls?= | last post by:
Hi, I have to upload large files using ASP.net on the remote server. Any ideas or suggestions would be of great help! Cheers Prasad
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
7
by: Bobby Edward | last post by:
Are there any ASP.NET compatible controls out there that will allow you to upload large files, up to 2 gb? Prefer free of course. ;)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.