【split 拷贝大文件分段拷贝】

在Rockchip平台的Android 7.1.2系统上,由于4GB文件上传限制,通常需要借助Linux的split命令对大文件进行切割以便上传。本文介绍如何使用split命令有效地分段拷贝大文件,并强调内容源于实战经验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

split 拷贝大文件分段拷贝


郑重声明:本人原创博文,都是实战,均经过实际项目验证出货的
转载请标明出处:攻城狮2015

Platform: Rockchip
OS:Android 7.1.2
Kernel: 3.10

问题描述

平常会遇到把大文件上传到网盘,但是超过4g就会提示,普通用户,超出最大上传限度。开发人员的文件,有时都几十G

解决方法

这个时候,就需要用到linux下的一个命令split,进行对文件压缩包切割

打包:tar zcvf YunOS_MPBranch.tar.gz YunOS_MPBranch
拆分:split -b 4000m YunOS_MPBranch.tar.gz YunOS_MPBranch.tar.gz.    --verbose
在C++中实现大文件分段读写可以通过以下骤进行: 1. 打开文件:使用C++的文件流对象,如`std::ifstream`和`std::ofstream`,打开需要读取或写入的文件。 2. 确定文件大小:可以使用文件流对象的`seekg`和`tellg`函数来确定文件的大小。`seekg`函数用于将文件指针移动到指定位置,`tellg`函数用于获取当前文件指针的位置。 3. 分段读取:根据需要设置每次读取的分段大小,可以使用`read`函数从文件中读取指定大小的数据块。读取的数据可以存储在缓冲区中供后续处理。 4. 分段写入:根据需要设置每次写入的分段大小,可以使用`write`函数将数据块写入文件中。写入的数据可以从缓冲区中获取。 5. 关闭文件:在读取或写入完成后,使用文件流对象的`close`函数关闭文件。 下面是一个示例代码,演示了如何实现大文件分段读写: ```cpp #include <iostream> #include <fstream> void splitFile(const std::string& inputFile, const std::string& outputFile, int segmentSize) { std::ifstream inFile(inputFile, std::ios::binary); std::ofstream outFile(outputFile, std::ios::binary); if (!inFile || !outFile) { std::cout << "Failed to open file!" << std::endl; return; } // 获取文件大小 inFile.seekg(0, std::ios::end); std::streampos fileSize = inFile.tellg(); inFile.seekg(0, std::ios::beg); // 分段读取和写入 char* buffer = new char[segmentSize]; std::streampos bytesRead = 0; while (bytesRead < fileSize) { int bytesToRead = (fileSize - bytesRead < segmentSize) ? (fileSize - bytesRead) : segmentSize; inFile.read(buffer, bytesToRead); outFile.write(buffer, bytesToRead); bytesRead += bytesToRead; } delete[] buffer; inFile.close(); outFile.close(); std::cout << "File split successfully!" << std::endl; } int main() { std::string inputFile = "input.txt"; std::string outputFile = "output.txt"; int segmentSize = 1024; // 每次读取或写入的分段大小 splitFile(inputFile, outputFile, segmentSize); return 0; } ``` 请注意,以上示例代码仅演示了如何实现大文件分段读写,并未处理异常情况和错误检查。在实际应用中,需要根据具体需求进行适当的错误处理和异常处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

攻城狮2015

你得打赏,是我的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值