![](/img/trans.png)
[英]Copy a file from sdcard location to another location in c language in Android
[英]Copy a certificate file to another location
我有一個.crl文件,我想復制到另一個位置。 從我到目前為止看到的所有帖子中,如果不復制內容就無法完成。 有什么方法可以在不復制內容的情況下將文件傳輸到cpp中的另一個位置?
我嘗試使用通常的fopen方法復制內容。 但是數據沒有被寫入緩沖區。 如果沒有直接方法,誰能告訴我如何讀取證書文件並將內容寫入另一個位置的另一個文件中?
我也嘗試了fstream方法
std::ofstream dest("destination.crl", std::ios::trunc|std::ios::binary);
if(!dest.good())
{ std::cerr << "error opening output file\n";
//std::exit(2);
}
std::fstream src("sourcec.crl", std::ios::binary);
if(!src.good())
{ std::cerr << "error opening input file\n";
//std::exit(1);
}
dest << src.rdbuf();
if(!src.eof()) std::cerr << "reading from file failed\n";
if(!dest.good()) std::cerr << "writing to file failed\n";
但是它顯示了錯誤:打開輸入文件從文件讀取失敗,寫入文件失敗
先感謝您
我在這里找到的。
看,這可能對您有幫助。 由於您不想閱讀,我以為您不想自己執行讀寫操作。
#include <istream>
#include <iostream>
#include <fstream>
#include <iterator>
using namespace std;
int main()
{
fstream f("source.crl", fstream::in|fstream::binary);
f << noskipws;
istream_iterator<unsigned char> begin(f);
istream_iterator<unsigned char> end;
fstream f2("destination.crl",
fstream::out|fstream::trunc|fstream::binary);
ostream_iterator<char> begin2(f2);
copy(begin, end, begin2);
}
根據您的回答,我寫另一個答案。
對於Window,具有功能[CopyFile][1]
。 您可以使用此功能復制文件,而無需自己閱讀內容。
對於基於linux / unix的應用程序,我無法找到CopyFile
的直接等效項。
我相信這個問題可能會對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.