{"id":19427,"date":"2025-10-11T18:44:08","date_gmt":"2025-10-11T10:44:08","guid":{"rendered":"https:\/\/www.bookcard.net\/wordpress\/?p=19427"},"modified":"2025-10-13T21:01:42","modified_gmt":"2025-10-13T13:01:42","slug":"android_studio_getfilesdir","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/android_studio_getfilesdir\/","title":{"rendered":"Android Studio-\u5167\u90e8\u5b58\u5132"},"content":{"rendered":"<figure id=\"attachment_19428\" aria-describedby=\"caption-attachment-19428\" style=\"width: 1280px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2025\/10\/Android_Studio_getFilesDir.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19428\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2025\/10\/Android_Studio_getFilesDir.jpg\" alt=\"Android Studio-\u5167\u90e8\u5b58\u5132\" width=\"1280\" height=\"800\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2025\/10\/Android_Studio_getFilesDir.jpg 1280w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2025\/10\/Android_Studio_getFilesDir-300x188.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2025\/10\/Android_Studio_getFilesDir-768x480.jpg 768w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/a><figcaption id=\"caption-attachment-19428\" class=\"wp-caption-text\">Android Studio-\u5167\u90e8\u5b58\u5132<\/figcaption><\/figure>\n<p>\u958b\u767c\u61c9\u7528\u7a0b\u5f0f,\u7e3d\u8981\u5b58\u5132\u5927\u91cf\u8a2d\u5b9a.\u4ee5\u4fbf\u91cd\u555f\u6642\u8b80\u53d6. \u4fc2android\u7cfb\u7d71\u5206\u300e\u5167\u90e8\u300f\u4edd\u300e\u5916\u90e8\u300f\u5b58\u5132.<\/p>\n<p>\u5167\u90e8\u5b58\u5132: \u8879\u6709\u7a0b\u5f0f\u80fd\u5920\u8a2a\u554f, \u5c6c\u65bc\u79c1\u4eba\u5409\u9593. \u6700\u91cd\u8981\u5187\u9700\u984d\u5916\u6b0a\u9650. \u4f46\u4fc2\u5409\u9593\u7d30, \u9069\u5b9c\u5b58\u5132\u7a0b\u5f0f\u8a2d\u5b9a. \u5378\u8f09\u7a0b\u5f0f\u5f8c\u6578\u64da\u81ea\u52d5\u6e05\u9664.<\/p>\n<p>\u5916\u90e8\u5b58\u5132: \u519a\u8fa6\u95cc\u5916\u90e8\u7a0b\u5f0f\u7686\u53ef\u8a2a\u554f,\u5c6c\u65bc\u516c\u773e\u5730\u65b9. \u9700\u8981\u984d\u5916\u6b0a\u9650. \u5409\u9593\u5927. \u9069\u5b9c\u5b58\u5132\u6587\u6a94. \u901a\u5e38\u4f4d\u65bcSD\u5361, \u6216\u8005\u4fc2\u78c1\u76e4\u7368\u7acb\u5283\u51fa\u5206\u5340\u5be6\u73fe. \u5378\u8f09\u7a0b\u5f0f\u5f8c\u6578\u64da\u4fdd\u7559.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"113\">\u5185\u90e8\u5b58\u5132<\/td>\n<td width=\"488\">getFilesDir()<\/td>\n<\/tr>\n<tr>\n<td width=\"113\">\u5916\u90e8\u5b58\u5132<\/td>\n<td width=\"488\">getExtemalFilesDir()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u300egetFilesDir()\u300f\u8fd4\u56de\u8def\u5f91\u5927\u7d04\u5982\u4e0b, \u9700\u7136\u53ef\u4ee5\u624b\u5de5\u751f\u6210, \u4f46\u4fc2\u6709\u53ef\u80fd\u8def\u5f91\u543e\u4edd. \u6240\u4ee5\u7e3d\u4fc2\u8abf\u7528\u300egetFilesDir()\u300f\u8fd4\u56de\u5185\u90e8\u5b58\u5132\u8def\u5f91.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">\/data\/data\/com.example.appname\/files<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u56e0\u300egetFilesDir()\u300f\u8fd4\u56deJAVA\u5b57\u7b26\u4e32, \u8981\u8f49\u70baC\u5b57\u7b26\u4e32.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">const char * path ;<br \/>\njboolean isCopy;<br \/>\npath = (*env).GetStringUTFChars( java_path, &amp;isCopy);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4fdd\u5b58\u8def\u5f91\u540e, \u8981\u91ca\u653eC\u5b57\u7b26\u4e32. \u5426\u5247\u9020\u6210\u8a18\u61b6\u9ad4\u6cc4\u6f0f.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">if(path != <strong>NULL<\/strong>)<br \/>\n(*env).ReleaseStringUTFChars(java_path,path );<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>C\u5275\u5efa\u5e76\u5beb\u5165\u6587\u6a94, \u7528\u300eopen()\u300f\u51fd\u5f0f<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">Int open(const char * pathame,int flags, \u2026 \/*mode_t mode*\/ );<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f15\u7528\u982d\u6587\u6a94<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"301\">#include &lt;fcntl.h&gt;<\/td>\n<td width=\"301\">open()\u51fd\u5f0f<\/td>\n<\/tr>\n<tr>\n<td width=\"301\">#include &lt;errno.h&gt;<\/td>\n<td width=\"301\">errno\u5168\u5c40\u8b8a\u91cf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"301\">flags:<\/td>\n<td width=\"301\">\u8a2a\u554f\u6a19\u8a18<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>O_WRONLY <\/strong><\/td>\n<td width=\"301\">\u8879\u5beb\u6a21\u5f0f<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>O_RDONLY<\/strong><\/td>\n<td width=\"301\"><strong>\u8879\u8b80\u6a21\u5f0f<\/strong><strong>\u200c<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>O_CREAT <\/strong><\/td>\n<td width=\"301\">\u5275\u5efa\u6587\u6a94<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>O_TRUNC <\/strong><\/td>\n<td width=\"301\">\u622a\u65b7\u6587\u6a94,\u9577\u5ea60.<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>O_APPEND <\/strong><\/td>\n<td width=\"301\">\u7e3d\u4fc2\u6587\u6a94\u5c58\u8ffd\u52a0\u6578\u64da<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"301\">mode<\/td>\n<td width=\"301\">\u6587\u6a94\u8b80\u5beb\u8a31\u53ef\u6b0a<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IWUSR <\/strong><\/td>\n<td width=\"301\">\u7528\u6236-\u5beb\u6b0a\u9650<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IRUSR <\/strong><\/td>\n<td width=\"301\">\u7528\u6236-\u8b80\u6b0a\u9650<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IRGRP<\/strong><\/td>\n<td width=\"301\">\u7fa4\u7d44-\u5beb\u6b0a\u9650<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IWGRP <\/strong><\/td>\n<td width=\"301\">\u7fa4\u7d44-\u8b80\u6b0a\u9650<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IROTH <\/strong><\/td>\n<td width=\"301\">\u5176\u4ed6\u7528\u6237 \u5beb\u6b0a\u9650<\/td>\n<\/tr>\n<tr>\n<td width=\"301\"><strong>S_IWOTH<\/strong><\/td>\n<td width=\"301\">\u5176\u4ed6\u7528\u6237 \u8b80\u6b0a\u9650<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u958b\u555f\u5beb\u6587\u6a94\u8981\u5275\u5efa\u6587\u6a94, \u6240\u4ee5\u4f60\u4ef2\u8981\u6307\u5b9a\u6587\u6a94\u8b80\u5beb\u6b0a\u9650.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">\u958b\u555f\u5beb\u6587\u6a94<\/td>\n<\/tr>\n<tr>\n<td width=\"601\">int flags = <strong>O_WRONLY <\/strong>| <strong>O_CREAT <\/strong>| <strong>O_TRUNC <\/strong>| <strong>O_APPEND <\/strong>;<\/td>\n<\/tr>\n<tr>\n<td width=\"601\">int mode = <strong>S_IWUSR <\/strong>| <strong>S_IRUSR <\/strong>| <strong>S_IRGRP <\/strong>| <strong>S_IWGRP <\/strong>| <strong>S_IROTH <\/strong>| <strong>S_IWOTH<\/strong>;<\/td>\n<\/tr>\n<tr>\n<td width=\"601\">int handle = open(filename, flags,\u00a0 mode);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u958b\u555f\u7957\u8b80\u6587\u6a94,\u5ffd\u518d\u8a2d\u7f5d\u6587\u6a94\u8b80\u5beb\u6b0a\u9650, \u5426\u5247<strong>\u300eerrno<\/strong><strong>\u300f\u8fd4\u56de\u300eEACCES<\/strong><strong>\u300f\u8a31\u53ef\u6b0a\u88ab\u62d2.<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">\u958b\u555f\u7957\u8b80\u6587\u6a94<\/td>\n<\/tr>\n<tr>\n<td width=\"601\">int handle = open(filename, <strong>O_RDONLY<\/strong>);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u958b\u767c\u61c9\u7528\u7a0b\u5f0f,\u7e3d\u8981\u5b58\u5132\u5927\u91cf\u8a2d\u5b9a.\u4ee5\u4fbf\u91cd\u555f\u6642\u8b80\u53d6. \u4fc2android\u7cfb\u7d71\u5206\u300e\u5167\u90e8\u300f\u4edd\u300e\u5916\u90e8\u300f\u5b58\u5132. \u5167\u90e8\u5b58\u5132:  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_studio_getfilesdir\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Android Studio-\u5167\u90e8\u5b58\u5132<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2],"class_list":["post-19427","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/19427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=19427"}],"version-history":[{"count":2,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/19427\/revisions"}],"predecessor-version":[{"id":19430,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/19427\/revisions\/19430"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=19427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=19427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=19427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}