我需要用c语言来访问像Downloads这样的文件夹 这是我的下载文件夹路径: /run/user/1002/gvfs/mtp:host=%5Busb%3A001%2C022%5D/下载/Download
我有java中的代码(可以工作),但不知道如何在c中做到这一点:
File root2 = android.os.Environment.getExternalStorageDirectory();
File sdcard = new File(root2.getAbsolutePath() + "/download");
sdcard.mkdirs();
File file = new File(sdcard, "XYZ1.txt");
if (!file.exists()) {
try {
file.createNewFile();
}catch (IOException e) {
}
}
我想知道如何用c语言访问Downloads文件夹 tnx寻求帮助
最佳答案
上面的等效 C 代码如下所示:-
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * fp;
FILE *fp = fopen("<relative/absolute path>/XYZ1.txt", "ab+"); //This create file if not present
if (fp==NULL){
printf("Could not create file in loc ..");
}
......
// Do your stuff with the file
......
fclose(fp); //Close the file before leaving
}
有关文件 IO 和文件访问模式的更多信息 here
关于java - C语言访问手机中的下载文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617286/