java文件分割器_JAVA学习课第五 — IO流程(九)文件分割器合成器

文件分割器

private static final int SIZE = 1024 *1024;

public static void splitFile(File file) throws IOException{

//用读取流关联文件(不确定文件格式)

FileInputStream fis = new FileInputStream(file);//源是一个

byte[] by = new byte[SIZE];//定义1M的缓冲区

FileOutputStream fos = null;//汇不知道有多少个

int len = 0;

int count = 1;//记录子文件个数

File dir = new File("D:\\patFiles");

if(!dir.isFile()){

dir.mkdirs();

}

while((len = fis.read(by))!=-1){

fos = new FileOutputStream(new File(dir,(count++)+".part"));//自己定义文件格式

fos.write(by,0,len);

}

fos.close();

fis.close();

}

文件合并

public static void main(String[] args) throws IOException {

File file = new File("D:\\PartFile");

Merge(file);

}

public static void Merge(File dir)throws IOException{

ArrayList AL = new ArrayList();

for(int i = 1;i<=7;i++){

AL.add(new FileInputStream(new File(dir,i+".part")));

}

Enumeration en = Collections.enumeration(AL);

SequenceInputStream sis = new SequenceInputStream(en);

FileOutputStream fos = new FileOutputStream(new File(dir,"盛夏光年.mp3"));

byte[] by = new byte[1024];

int len = 0;

while((len = sis.read(by))!=-1){

fos.write(by, 0, len);

}

sis.close();

fos.close();

}

文件分割合并+配置文件

import java.io.*;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Enumeration;

import java.util.Properties;

public class Main

{

private static final int SIZE = 1024 *1024;

public static void main(String[] args) throws IOException {

File file1 = new File("d:\\NeedSplit\\盛夏光年.mp3");

File file2 = new File("D:\\PartFiles");

splitFile(file1);

Merge_1(file2);

}

public static void splitFile(File file) throws IOException{

//用读取流关联文件(不确定文件格式)

FileInputStream fis = new FileInputStream(file);//源是一个

byte[] by = new byte[SIZE];//定义1M的缓冲区

FileOutputStream fos = null;//汇不知道有多少个

int len = 0;

int count = 1;//记录子文件个数

/*分割文件必需要记录分割文件的名称和分割处理的碎片文件的个数,方便合并

* 这个信息为了进行描写叙述,使用键值对的方法。所以使用Properties对象*/

Properties pro = new Properties();

File dir = new File("D:\\PartFiles");

if(!dir.isFile()){

dir.mkdirs();

}

while((len = fis.read(by))!=-1){

fos = new FileOutputStream(new File(dir,(count++)+".part"));//自己定义文件格式

fos.write(by,0,len);

fos.close();

}

//将分割后文件的信息保存在pro集合中

pro.setProperty("partCount", count+"");

pro.setProperty("fileName", file.getName());

fos = new FileOutputStream(new File(dir,count+".properties"));

//将pro集合的信息存储在集合中

pro.store(fos, "save file infmation");

fis.close();

}

public static void Merge_1(File dir)throws IOException{

//获取指定文件夹下配置文件对象

File[] files = dir.listFiles(new SuffixFilter(".properties"));//new一个过滤器

if(files.length!=1){

throw new RuntimeException(dir+"该文件夹下没有properties扩展名的文件或者不唯一 ");

}

//记录配置文件对象

File confile = files[0];

//获取配置文件信息

Properties pro = new Properties();

FileInputStream fis = new FileInputStream(confile);//关联流对象

pro.load(fis);//载入信息

String filename = pro.getProperty("fileName");//得到文件名称

int count = Integer.parseInt(pro.getProperty("partCount"));//得到碎片个数

//获取该文件夹下的全部碎片文件

//定义过滤器。推断碎片文件的个数与配置信息中的碎片信息是否一致

File[] partFiles = dir.listFiles(new SuffixFilter(".part"));

if(partFiles.length!=(count-1)){

throw new RuntimeException("碎片文件个数不正确,应是"+count+"个!");

}

//将碎片文件和流对象关联。并存储集合中

ArrayList AL = new ArrayList();

for(int i = 0;i

AL.add(new FileInputStream(partFiles[i]));

}

//将多个流合并成一个序列流

Enumeration en = Collections.enumeration(AL);

SequenceInputStream sis = new SequenceInputStream(en);

//读写过程

FileOutputStream fos = new FileOutputStream(new File(dir,filename));

byte[] by = new byte[1024];

int len = 0;

while((len = sis.read(by))!=-1){

fos.write(by, 0, len);

}

sis.close();

fos.close();

}

}

版权声明:本文博主原创文章。博客,未经同意不得转载。

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值