• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to split a file in java  RSS feed

 
ramjcp kris
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All

i have a text file which is of size 6 mb,which i need to send across net.
so i want to split this file in 2 files, which is of 3mb each.

can any one suggest me How can i split a file in java when its size is more than say 6mb.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can manually do it by getting the size of the file through the length() method on the file and you can split it accordingly.

length() method returns a long value - FYI. [as per Java 2]

i m not sure which version of JDK you use and the support the higher versions have (Tiger, Mustang). Just check the respective JavaDocs for the same.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to read and write files? If not, the Java Tutorial IO chapter is a good place to start.
I'm curious, why are you splitting the file? There's no arbitrary limit to the length of a stream. Do you have a receiving process that will reassemble the file?
 
ramjcp kris
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to split file because , iwant to send these files over queue.
but my queue limit is 4MB, so i cant send file of size more than 4mb to a queue. if my file size is more than 4mb , i need to split it and send over queue
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. So have you read the tutorial? Can you read/write files? What specifically do you need a hand with?
 
rohit leeta
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check source code of this application:

Java File Splitter v1.0
http://www.programmersheaven.com/download/30541/download.aspx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!