Linux 下如何用SD卡存储用户行为数据存储

数据库错误
建立数据库连接时出错Android数据存储与访问之使用SD卡_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Android数据存储与访问之使用SD卡
来源:Linux社区&
作者:t12x3456
使用Activity的openFileOutput()方法保存文件,文件是存放在手机空间上,一般手机的存储空间不是很大,存放些小文件还行,如果要存放像视频这样的大文件,是不可行的。对于像视频这样的大文件,我们可以把它存放在SDCard。 SDCard是干什么的?你可以把它看作是移动硬盘或U盘。在模拟器中使用SDCard,你需要先创建一张SDCard卡(当然不是真的SDCard,只是镜像文件)。创建SDCard可以在Eclipse创建模拟器时随同创建,也可以使用DOS命令进行创建,如下:在Dos窗口中进入 SDK安装路径的tools目录,输入以下命令创建一张容量为2G的SDCard,文件后缀可以随便取,建议使用.img:mksdcard 2048M D:\AndroidTool\sdcard.img在程序中访问SDCard,你需要申请访问SDCard的权限。在AndroidManifest.xml中加入访问SDCard的权限如下:&!-- 在SDCard中创建与删除文件权限 --&&uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/&&!-- 往SDCard写入数据权限 --&&uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&
要往SDCard存放文件,程序必须先判断手机是否装有SDCard,并且可以进行读写。注意:访问SDCard必须在AndroidManifest.xml中加入访问SDCard的权限if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){&&&&&&&& File sdCardDir = Environment.getExternalStorageDirectory();//获取SDCard目录&&&&&&&& File saveFile = new File(sdCardDir, “hello.txt”);FileOutputStream outStream = new FileOutputStream(saveFile);outStream.write("test".getBytes());outStream.close();}Environment.getExternalStorageState()方法用于获取SDCard的状态,如果手机装有SDCard,并且可以进行读写,那么方法返回的状态等于Environment.MEDIA_MOUNTED。Environment.getExternalStorageDirectory()方法用于获取SDCard的目录,当然要获取SDCard的目录,你也可以这样写:File sdCardDir = new File("/mnt/sdcard"); //获取SDCard目录File saveFile = new File(sdCardDir, "itcast.txt"); //上面两句代码可以合成一句: File saveFile = new File("/mnt/sdcard/hello.txt");FileOutputStream outStream = new FileOutputStream(saveFile);outStream.write("test".getBytes());outStream.close();
相关资讯 & & &
& (11/13/:33)
& (09/13/:16)
& (09/13/:32)
& (11/13/:11)
& (09/13/:53)
& (09/13/:15)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款&nbsp>&nbsp
&nbsp>&nbsp
&nbsp>&nbsp
C语言中linux下查看sd卡mount的位置
摘要:linux查找sd卡mount的位置:#include&sstream&//std::istringstream#include&stdio.h&//FILEandpopen#include&string&......其他头文件......std::stringgetSDCardPath();主函数(getSDFCardPath);......其他函数......std::stringgetSDCardPath(){FILE*char
linux 查找sd卡mount的位置:
#include&sstream& //std::istringstream
#include&stdio.h& //FILE and popen
#include&string&
......其他头文件......
std::string getSDCardPath();
主函数(getSDFCardPath);
......其他函数......
std::string getSDCardPath()
FILE *char buffer[80];std::std::string tmpPath[3];if((fp = popen(&mount|grep /dev/sdcard&,r)) == NULL)std::cout && &failed& && std:://调用shell, r表示读,其中/dev/sdcard 是系统默认的sd卡的名字,也有可能是mmcblk0,mmcblk0p1fgets(buffer,sizeof(char)*80,fp);//从fp中取出80个字到buffer中std::string str(buffer);std:://按空格切分string&for(int i = 0;i != 3;++i){iss && tmpPath[i];}return tmpPath[2];}说说popen函数:FILE * popen ( const char * command , const char * type );int pclose ( FILE * stream );popen() 函数通过创建一个管道,调用 fork 产生一个子进程,执行一个 shell 以运行命令来开启一个进程。这个进程必须由&pclose() 函数关闭,而不是 fclose() 函数。pclose() 函数关闭标准 I/O 流,等待命令执行结束,然后返回 shell 的终止状态。如果 shell 不能被执行,则 pclose() 返回的终止状态与 shell 已执行 exit 一样。type 参数只能是读或者写中的一种,得到的返回值(标准 I/O 流)也具有和 type 相应的只读或只写类型。如果 type 是 &r&&则文件指针连接到 command 的标准输出;如果 type 是 &w& 则文件指针连接到 command 的标准输入。command 参数是一个指向以 NULL 结束的 shell 命令字符串的指针。这行命令将被传到 bin/sh 并使用-c 标志,shell 将执行这个命令。popen 的返回值是个标准 I/O 流,必须由 pclose 来终止。前面提到这个流是单向的。所以向这个流写内容相当于写入该命令的标准输入;命令的标准输出和调用 popen 的进程相同。与之相反的,从流中读数据相当于读取命令的标准输出;命令的标准输入和调用 popen 的进程相同。函数的返回值:如果调用 fork() 或 pipe() 失败,或者不能分配内存将返回NULL,否则返回标准 I/O 流。popen 没有为内存分配失败设置 errno 值。如果调用 fork() 或 pipe() 时出现错误,errno 被设为相应的错误类型。如果 type 参数不合法,errno将返回EINVAListringstream的功能是网上查的,需要了解可以自行查看
以上是的内容,更多
的内容,请您使用右上方搜索功能获取相关信息。
若你要投稿、删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内给你回复。
云服务器 ECS
可弹性伸缩、安全稳定、简单易用
&40.8元/月起
预测未发生的攻击
&24元/月起
邮箱低至5折
推荐购买再奖现金,最高25%
&200元/3月起
你可能还喜欢
你可能感兴趣
阿里云教程中心为您免费提供
C语言中linux下查看sd卡mount的位置相关信息,包括
的信息,所有C语言中linux下查看sd卡mount的位置相关内容均不代表阿里云的意见!投稿删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内答复
售前咨询热线
支持与服务
资源和社区
关注阿里云
International温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(8314)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'LINUX下的SD卡分区',
blogAbstract:'
打开终端,然后根据提示输入以下命令:
输入sudo fdisk /dev/sdb
回车 这时我们可以看到系统里的分区有情况, 系统的盘符是 ',
blogTag:'linux,分区',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:5,
publishTime:1,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}I have a Debian 7.0 Linux 3.2 embedded ARM TI AM335x system.
This is a custom board we've developed, but the SD card section at least is the same as the development board.
There are some vendor-specific SD card commands I'd like to issue to the card, namely reading some SMART data using CMD56.
Is there any way to send commands to the SD card controller and read the response from userspace?
解决方案 Your driver is
according to
some info also in
After some web searching for SMART monitoring support in sd cards, I get the search query mmc smartctl (because smartctl is name of SMART monitoring utility for *ATA in Linux, and mmc is the kernel subsystem to implement MMC, SD, SDHC cards and controllers. I found the bug filled against some mobile PC OS,
by Gwendal Grignou
If the root device is a SATA device:
Add output of hdparm -I /dev/sda
Add output of smartctl -a /dev/sda
If the root device is a eMMC device:
When mmc-utils will be part of the image, add a similar command output.
It sounds like the mmc-utils it the tool of choice to implement SMART for SD cards. There is home git of mmc-utils on kernel.org:
I see no "SMART" here, but the
has code to send custom commands to the card by using ioctl(fd, MMC_IOC_CMD, (struct mmc_ioc_cmd*) &ioctl_data) with fd pointing to correct mmcblkX device (I hope this works with most SD controllers). Code by Johan RUDHOLM (from st-ericsson, 2012, GPLv2):
int read_extcsd(int fd, __u8 *ext_csd)
struct mmc_ioc_
memset(&idata, 0, sizeof(idata));
memset(ext_csd, 0, sizeof(__u8) * 512);
idata.write_flag = 0;
idata.opcode = MMC_SEND_EXT_CSD;
idata.arg = 0;
idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
idata.blksz = 512;
idata.blocks = 1;
mmc_ioc_cmd_set_data(idata, ext_csd);
ioctl(fd, MMC_IOC_CMD, &idata);
int write_extcsd_value(int fd, __u8 index, __u8 value)
struct mmc_ioc_
memset(&idata, 0, sizeof(idata));
idata.write_flag = 1;
idata.opcode = MMC_SWITCH;
idata.arg = (MMC_SWITCH_MODE_WRITE_BYTE && 24) |
(index && 16) |
(value && 8) |
EXT_CSD_CMD_SET_NORMAL;
idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
return ioctl(fd, MMC_IOC_CMD, &idata);
Some documentation and examples for MMC_IOC_CMD were posted in LKML by Shashidhar Hiremath at 20 Dec 14:54 2011
The official userAPI (uapi) for struct mmc_ioc_cmd is in linux source tree :
6 struct mmc_ioc_cmd {
/* Application-specific command.
true = precede with CMD55 */
* Since this ioctl is only meant to enhance (and not replace) normal access
* to the mmc bus device...
本文地址: &
我有一个Debian的Linux 7.0 3.2嵌入式ARM TI AM335x系统。这是我们开发了定制电路板,但SD卡部分至少是一样的开发板。有一些供应商特定SD卡的命令,我想发出的卡,即采用阅读一些CMD56 SMART数据。有没有办法将命令发送到SD卡控制器,并读取用户空间的反应?解决方案 您驱动程序是omap_hsmmc根据http://processors.wiki.ti.com/index.php/AM335x_MMC/SD_Driver%27s_Guide一些信息也是https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt在一些的网站的搜索在SD卡智能监控支持,我得到的搜索查询 MMC smartctl读取(因为 smartctl读取中的Linux * ATA SMART监控工具的名称, MMC 是实现MMC,SD,SDHC卡和控制器的内核子系统。我发现的bug充满对抗的一些移动PC操作系统的https://$c$c.google.com/p/chromium/issues/detail?id=315380通过Gwendal Grignou
如果根设备是一个SATA设备:
添加hdparm的 - 我的/ dev / sda的输出
添加-a smartctl读取的/ dev / sda的输出
如果根设备是一个eMMC的设备:
当MMC-utils的将是图像的一部分,添加一个类似命令的输出。
这听起来像 MMC-utils的它选择的工具来实施智能SD卡。有在kernel.org
MMC-utils的的家的git:http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/我没有看到“SMART”在这里,但mmc-utils/mmc_cmds.c有code发送使用的ioctl自定义命令到卡(FD,MMC_IOC_CMD,(结构mmc_ioc_cmd *)及ioctl_data)与FD指向正确的 mmcblkX 设备(我希望这个作品与大多数SD控制器)。由Johan RUDHOLM code(从ST-Ericsson的,2012年,在GPLv2):
INT read_extcsd(INT FD,__u8 * ext_csd)
结构mmc_ioc_cmd IDATA;
memset的(安培; IDATA,0,sizeof的(IDATA));
memset的(ext_csd,0,sizeof的(__ U8)* 512);
idata.write_flag = 0;
idata.op code = MMC_SEND_EXT_CSD;
idata.arg = 0;
idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
idata.blksz = 512;
idata.blocks = 1;
mmc_ioc_cmd_set_data(IDATA,ext_csd);
返回的ioctl(FD,MMC_IOC_CMD,&安培; IDATA);
INT write_extcsd_value(INT FD,__u8指数,__u8值)
结构mmc_ioc_cmd IDATA;
memset的(安培; IDATA,0,sizeof的(IDATA));
idata.write_flag = 1;
idata.op code = MMC_SWITCH;
idata.arg =(MMC_SWITCH_MODE_WRITE_BYTE<< 24)|
(指数<< 16)|
(价值<< 8)|
EXT_CSD_CMD_SET_NORMAL;
idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
返回的ioctl(FD,MMC_IOC_CMD,&安培; IDATA);
} 有关MMC_IOC_CMD一些文档和例子是在LKML 20张贴Shashidhar Hiremath十二月14:54 2011
为结构mmc_ioc_cmd 官方userAPI(uapi)是在Linux源代码树include/uapi/linux/mmc/ioctl.h:
6结构mmc_ioc_cmd {... 10 / *应用程序特定的命令。真正= precede与CMD55 * / 11 INT is_... 51 *由于此读写控制只是为了提升(而不是取代)正常访问 52 *到MMC总线设备...
本文地址: &
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
(window.slotbydup = window.slotbydup || []).push({
id: '5828425',
container: s,
size: '300,250',
display: 'inlay-fix'}

我要回帖

更多关于 存储用户关系的数据库 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信