代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
大文件的分割与合并
作者:
周明瑞
/ 发布于
2013/2/17
/
886
java处理大文件的分割与合并,电影等,文本文件没有尝试,我也说不好行不行,今天忙了很长时间才设计出的界面
package com.mingrui.test; import java.io.*; import java.util.Enumeration; import java.util.Vector; import java.awt.*; import java.awt.event.*; import javax.media.rtp.event.NewParticipantEvent; import javax.swing.*; public class Test18_15 extends JFrame{ private int part=2; private File file=null; private File []files=null; //icon private ImageIcon icon_but_fege_right=new ImageIcon("img/fen_ge_right.png"); private ImageIcon icon_but_hebing_ringht=new ImageIcon("img/he_bing_right.png"); private ImageIcon icon_tiaofu=new ImageIcon("img/tiao_fu.jpg"); private ImageIcon icon_but_hebing=new ImageIcon("img/but_hebing.png"); private ImageIcon icon_jl_hebing=new ImageIcon("img/hebing_left.png"); private ImageIcon icon_mr=new ImageIcon("img/mr.png"); //jlabel private JLabel jl_tiaofu=new JLabel(new ImageIcon("img/icon_tiaofu.png")); private JLabel jl_hebing=new JLabel(new ImageIcon("img/hebing_left.png")); //jbutton private JButton jb_hebing_right=new JButton("???",new ImageIcon("img/he_bing_right.png")); private JButton jb_fege_right=new JButton("???",new ImageIcon("img/fen_ge_right.png")); private JButton jb_hebing=new JButton("????????????",new ImageIcon("img/but_hebing.png")); private JButton jb_fege=new JButton("???????????",new ImageIcon("img/but_fenge.png")); private JButton jb_zouni=new JButton(new ImageIcon("img/zouni.png")); private JButton jb_zouni1=new JButton(new ImageIcon("img/zouni.png")); //jpanel private JPanel jp_right=new JPanel(); private JPanel jp_bottom_total=new JPanel(); private JPanel jp_left=new JPanel(); private JPanel jp_left_up_hebing=new JPanel(); private JPanel jp_left_up_fenge=new JPanel(); private JPanel jp_left_hebing=new JPanel(); private JPanel jp_left_fenge=new JPanel(); //???? private CardLayout cl=new CardLayout(); //???? private DrawPanel dp_fenge=new DrawPanel(); private DrawPanel dp_hebing=new DrawPanel(); //?????б? private JComboBox jcbo; private String[] str={"2","3","4","5","6"}; private FileSeparate fsp; private FileCombiner fcb; Test18_15(){ super("??????????"); super.setIconImage(icon_mr.getImage()); fsp=new FileSeparate(dp_fenge); fcb=new FileCombiner(dp_hebing); jb_fege_right.setBorderPainted(false); jb_hebing_right.setBorderPainted(false); jb_fege_right.setBackground(new Color(2766386)); jb_hebing_right.setBackground(new Color(2766386)); jb_zouni.setBackground(new Color(2766386)); jb_zouni1.setBackground(new Color(2766386)); jcbo=new JComboBox<>(str); jcbo.setBackground(new Color(2981939)); jp_left.setLayout(cl); dp_hebing.setBackground(new Color(14015449)); jp_left.add(jp_left_hebing, "hebing"); jp_left.add(jp_left_fenge,"fenge"); jp_right.setLayout(new GridLayout(2, 1)); jp_right.add(jb_fege_right); jp_right.add(jb_hebing_right); //??????? jp_left_up_hebing.setBackground(new Color(2766386)); //jb_hebing.setBackground(new Color(2766386)); jp_left_up_hebing.add(jb_hebing); jp_left_up_hebing.add(jl_hebing); jp_left_up_hebing.add(jb_zouni); jp_left_up_fenge.setBackground(new Color(2766386)); jp_left_up_fenge.add(jb_fege); jp_left_up_fenge.add(jcbo); jp_left_up_fenge.add(jb_zouni1); jp_left_hebing.setLayout(new BorderLayout()); jp_left_fenge.setLayout(new BorderLayout()); jp_left_hebing.add(jp_left_up_hebing,BorderLayout.NORTH); jp_left_hebing.add(dp_hebing,BorderLayout.CENTER); jp_left_fenge.add(jp_left_up_fenge,BorderLayout.NORTH); jp_left_fenge.add(dp_fenge,BorderLayout.CENTER); jp_bottom_total.setLayout(new BorderLayout()); jp_bottom_total.add(jp_left,BorderLayout.CENTER); jp_bottom_total.add(jp_right,BorderLayout.EAST); setLayout(new BorderLayout()); add(jl_tiaofu,BorderLayout.NORTH); add(jp_bottom_total,BorderLayout.CENTER); jb_fege_right.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub cl.show(jp_left, "fenge"); } }); jb_hebing_right.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub cl.show(jp_left, "hebing"); } }); jb_hebing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub dp_hebing.setStr1("being choose your file"); dp_hebing.repaint(); JFileChooser jfc=new JFileChooser(); jfc.setMultiSelectionEnabled(true); int returnVal=jfc.showOpenDialog(null); if(returnVal==JFileChooser.APPROVE_OPTION){ files=jfc.getSelectedFiles(); } } }); jb_fege.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFileChooser jfc=new JFileChooser(); int returnVal=jfc.showOpenDialog(null); //jfc.setMultiSelectionEnabled(true); //jfc.setCurrentDirectory(new File("")); if(returnVal==JFileChooser.APPROVE_OPTION){ file=jfc.getSelectedFile(); } } }); jb_zouni.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(files!=null) fcb.setFiles(files); try { fcb.setFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); jb_zouni1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(file!=null){ fsp.setFileCount(part); fsp.setFile(file); } } }); jcbo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub part=jcbo.getSelectedIndex()+2; } }); } public static void main(String[] args) { // TODO Auto-generated method stub Test18_15 frame=new Test18_15(); frame.setSize(600,550); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(3); frame.setVisible(true); frame.setResizable(false); } } class DrawPanel extends JPanel{ private Color colorWord; private Color colorLine; private String str="you are being the file function panel"; private String str1="processing......"; private String str2="file location:"; private String str3=""; protected void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(colorLine); g.drawLine(0, 10, getWidth(), 10); g.drawLine(0, 12, getWidth(), 12); g.drawLine(getWidth()-10, 0, getWidth()-10, getHeight()); g.drawLine(0, getHeight()-10, getWidth(), getHeight()-10); g.drawLine(0, getHeight()-8, getWidth(), getHeight()-8); g.drawLine(0, getHeight()-12, getWidth(), getHeight()-12); g.drawLine(0, getHeight()-14, getWidth(), getHeight()-14); g.drawLine(10, 0, 10, getWidth()); g.drawLine(12, 0, 12, getWidth()); g.drawLine(14, 0, 14, getWidth()); g.drawLine(16, 0, 16, getWidth()); g.setColor(new Color(11118449)); g.setFont(new Font("Brush script MT",Font.ITALIC,25)); g.drawString(str, 23, 35); g.setColor(Color.red); g.drawString(str1, 23, 65); g.drawString(str2, 23, 95); g.drawString(str3, 23, 125); g.setFont(new Font("Microsoft YaHei UI",Font.BOLD,15)); g.setColor(Color.green); g.drawString("?????????????", 23, 248); g.drawString("??????????????в???", 23, 288); g.setColor(Color.orange); g.drawString("??????????????????????С??---????", 23, 328); } public Color getColorWord() { return colorWord; } public void setColorWord(Color colorWord) { this.colorWord = colorWord; } public Color getColorLine() { return colorLine; } public void setColorLine(Color colorLine) { this.colorLine = colorLine; } public void setStr(String str){ this.str=str; } public void setStr1(String str1){ this.str1=str1; } public void setStr3(String str3){ this.str3=str3; } } class FileSeparate{ private int fileCount=0; private int soloFileSize=0; private byte [] buf; private boolean isTxt=false; private static final String OUTFILES="D:"; private DataOutputStream [] doss; DrawPanel dp; //private BufferedWriter [] buw; FileSeparate(DrawPanel dp){ this.dp=dp; } public void setTxt(boolean isTxt){ this.isTxt=isTxt; } public boolean isTxt(){ return isTxt; } public void setFile(File file){ try { doss=new DataOutputStream[fileCount]; this.setFileCount(fileCount); DataInputStream dis=new DataInputStream(new BufferedInputStream(new FileInputStream(file))); int cl=0; if(!isTxt){ int l=dis.available()/1024/1024; soloFileSize=(int)(l/fileCount)+1; if(soloFileSize>=1&&soloFileSize<=300) buf=new byte[soloFileSize*1024*1024]; for(int i=0;i<fileCount;i++){ doss[i]=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File("d:/"+i+".part")))); } while(dis.read(buf)!=-1){ doss[cl].write(buf); doss[cl++].close(); } dp.setColorWord(new Color(8388608)); dp.setStr1("yes we have finished"); dp.setStr3("D???μ?x.part"); dp.repaint(); } else{} } catch (FileNotFoundException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getFileDirectory(){ return OUTFILES; } public int getFileCount() { return fileCount; } public void setFileCount(int fileCount) { this.fileCount = fileCount; } } class FileCombiner{ private File []files; private int fileCount=0; private byte []buf=new byte[1024*1024]; private static final String OUTFILES="D:\finished.file"; private DrawPanel dp; FileCombiner(DrawPanel dp){ this.dp=dp; } public void setFile() throws IOException{ Vector<DataInputStream> v=new Vector<DataInputStream>(); for(int i=0;i<files.length;i++){ v.add(new DataInputStream(new BufferedInputStream(new FileInputStream(files[i])))); } Enumeration e=v.elements(); SequenceInputStream sis=new SequenceInputStream(e); DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(new FileOutputStream("D:/finished.file"))); while(sis.read(buf)!=-1){ dos.write(buf); } dp.setColorWord(new Color(8388608)); dp.setStr1("yes all have done"); dp.repaint(); dp.setStr3("D???μ?finished.file"); dos.close(); sis.close(); } public String getFileDirectory(){ return OUTFILES; } public int getFileCount() { return fileCount; } public void setFileCount(int fileCount) { this.fileCount = fileCount; } public File [] getFiles() { return files; } public void setFiles(File [] files) { this.files = files; } }
试试其它关键字
分割与合并
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
周明瑞
贡献的其它代码
(
3
)
.
Java解决迷宫问题
.
大文件的分割与合并
.
java判断点在三角形内
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3