Merge "docs: fix syntax error in "Saving Files" document" into nyc-dev
This commit is contained in:
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,7 +250,7 @@ public boolean isExternalStorageReadable() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>たとえば、自分のアプリでダウンロードした追加のリソースや一時的なメディア ファイルです。</p>
|
<p>たとえば、自分のアプリでダウンロードした追加のリソースや一時的なメディア ファイルです。</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES} などの保存するファイルの
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ android.content.Context#getExternalFilesDir getExternalFilesDir()} を呼び出
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -366,7 +366,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>注:</strong> ユーザーがアプリをアンインストールすると、Android システムは次を削除します。
|
<p><strong>注:</strong> ユーザーがアプリをアンインストールすると、Android システムは次を削除します。
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>内部ストレージに保存したすべてのファイル</li>
|
<li>内部ストレージに保存したすべてのファイル</li>
|
||||||
<li>{@link
|
<li>{@link
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,7 +250,7 @@ public boolean isExternalStorageReadable() {
|
|||||||
앱을 제거하면 같이 삭제됩니다. 이러한 파일은
|
앱을 제거하면 같이 삭제됩니다. 이러한 파일은
|
||||||
엄밀히 말해 외부 저장소에 저장된 파일이기 때문에 사용자 및 다른 앱의 액세스가 가능하긴 하지만, 앱 외부에서
|
엄밀히 말해 외부 저장소에 저장된 파일이기 때문에 사용자 및 다른 앱의 액세스가 가능하긴 하지만, 앱 외부에서
|
||||||
사용자에게 값을 실제로 제공하지는 않습니다. 사용자가 앱을 제거하면 앱의 외부 개인 디렉터리 내 모든 파일을 시스템에서
|
사용자에게 값을 실제로 제공하지는 않습니다. 사용자가 앱을 제거하면 앱의 외부 개인 디렉터리 내 모든 파일을 시스템에서
|
||||||
삭제합니다.
|
삭제합니다.
|
||||||
<p>예를 들어 앱에서 다운로드한 추가 리소스 또는 임시 미디어 파일이 이에 해당합니다.</p>
|
<p>예를 들어 앱에서 다운로드한 추가 리소스 또는 임시 미디어 파일이 이에 해당합니다.</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES}와 같은 다른 공개
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ android.content.Context#getExternalFilesDir getExternalFilesDir()}을 호출하
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -357,7 +357,7 @@ JPEG로 변환하여 파일 인코딩을
|
|||||||
myFile.delete();
|
myFile.delete();
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>파일이 내부 저장소에 저장되어 있는 경우, {@link android.content.Context}에 위치를 요청하고 {@link android.content.Context#deleteFile deleteFile()}을 호출하여 파일을
|
<p>파일이 내부 저장소에 저장되어 있는 경우, {@link android.content.Context}에 위치를 요청하고 {@link android.content.Context#deleteFile deleteFile()}을 호출하여 파일을
|
||||||
삭제할 수도 있습니다.</p>
|
삭제할 수도 있습니다.</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@@ -366,7 +366,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>참고:</strong> 사용자가 앱을 제거하면 Android 시스템이
|
<p><strong>참고:</strong> 사용자가 앱을 제거하면 Android 시스템이
|
||||||
다음 항목을 삭제합니다.</p>
|
다음 항목을 삭제합니다.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>내부 저장소에 저장한 모든 파일</li>
|
<li>내부 저장소에 저장한 모든 파일</li>
|
||||||
<li>{@link
|
<li>{@link
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,12 +250,12 @@ o usuário deve continuar a ter acesso a esses arquivos.
|
|||||||
. Embora esses arquivos estejam teoricamente à disposição do usuário e de outros aplicativo por estarem
|
. Embora esses arquivos estejam teoricamente à disposição do usuário e de outros aplicativo por estarem
|
||||||
no armazenamento externo, na verdade são arquivos que não têm valor para o usuário
|
no armazenamento externo, na verdade são arquivos que não têm valor para o usuário
|
||||||
fora do aplicativo. Ao desinstalar o aplicativo, o sistema exclui
|
fora do aplicativo. Ao desinstalar o aplicativo, o sistema exclui
|
||||||
todos os arquivos no diretório privado externo do aplicativo.
|
todos os arquivos no diretório privado externo do aplicativo.
|
||||||
<p>Por exemplo, recursos adicionais baixados através do aplicativo ou arquivos de mídia temporários.</p>
|
<p>Por exemplo, recursos adicionais baixados através do aplicativo ou arquivos de mídia temporários.</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<p>Para salvar arquivos públicos no armazenamento externo, use o método
|
<p>Para salvar arquivos públicos no armazenamento externo, use o método
|
||||||
{@link android.os.Environment#getExternalStoragePublicDirectory
|
{@link android.os.Environment#getExternalStoragePublicDirectory
|
||||||
getExternalStoragePublicDirectory()} para obter um {@link java.io.File} que representa
|
getExternalStoragePublicDirectory()} para obter um {@link java.io.File} que representa
|
||||||
o diretório correto no armazenamento externo. O método exige um argumento que especifica
|
o diretório correto no armazenamento externo. O método exige um argumento que especifica
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES}. Por exemplo:</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ usuário faz a desinstalação.</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -366,7 +366,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>Observação:</strong> quando o usuário desinstala o aplicativo, o sistema Android também
|
<p><strong>Observação:</strong> quando o usuário desinstala o aplicativo, o sistema Android também
|
||||||
exclui:</p>
|
exclui:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Todos os arquivos salvos no armazenamento interno</li>
|
<li>Todos os arquivos salvos no armazenamento interno</li>
|
||||||
<li>Todos os arquivos salvos no armazenamento externo usando {@link
|
<li>Todos os arquivos salvos no armazenamento externo usando {@link
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,7 +250,7 @@ public boolean isExternalStorageReadable() {
|
|||||||
вашего приложения пользователем. Хотя технически эти файлы доступны для пользователя и других приложений, поскольку находятся
|
вашего приложения пользователем. Хотя технически эти файлы доступны для пользователя и других приложений, поскольку находятся
|
||||||
во внешнем хранилище, они не имеют никакой ценности для пользователей
|
во внешнем хранилище, они не имеют никакой ценности для пользователей
|
||||||
вне вашего приложения. Когда пользователь удаляет ваше приложение, система удаляет
|
вне вашего приложения. Когда пользователь удаляет ваше приложение, система удаляет
|
||||||
все файлы из каталога закрытых файлов вашего приложения во внешнем хранилище.
|
все файлы из каталога закрытых файлов вашего приложения во внешнем хранилище.
|
||||||
<p>Например, к этой категории относятся дополнительные ресурсы, загруженные приложением, и временные мультимедийные файлы.</p>
|
<p>Например, к этой категории относятся дополнительные ресурсы, загруженные приложением, и временные мультимедийные файлы.</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES}. Например:</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ android.content.Context#getExternalFilesDir getExternalFilesDir()} и предо
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -332,7 +332,7 @@ java.io.File#getTotalSpace}. Эти методы позволяют узнать
|
|||||||
общее пространство в хранилище. Эта информация также позволять
|
общее пространство в хранилище. Эта информация также позволять
|
||||||
избежать переполнения объема хранилища сверх определенного уровня.</p>
|
избежать переполнения объема хранилища сверх определенного уровня.</p>
|
||||||
|
|
||||||
<p>Однако система не гарантирует возможность записи такого же количества байт, как указано
|
<p>Однако система не гарантирует возможность записи такого же количества байт, как указано
|
||||||
в {@link java.io.File#getFreeSpace}. Если выводимое число на
|
в {@link java.io.File#getFreeSpace}. Если выводимое число на
|
||||||
несколько мегабайт превышает размер данных, которые вы хотите сохранить, или если файловая система заполнена
|
несколько мегабайт превышает размер данных, которые вы хотите сохранить, или если файловая система заполнена
|
||||||
менее, чем на 90%, дальше можно действовать спокойно.
|
менее, чем на 90%, дальше можно действовать спокойно.
|
||||||
@@ -366,13 +366,13 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>Примечание.</strong> При удалении пользователем вашего приложения система Android удаляет
|
<p><strong>Примечание.</strong> При удалении пользователем вашего приложения система Android удаляет
|
||||||
следующие элементы:</p>
|
следующие элементы:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Все файлы, сохраненные во внутреннем хранилище</li>
|
<li>Все файлы, сохраненные во внутреннем хранилище</li>
|
||||||
<li>Все файлы, сохраненные во внешнем хранилище с использованием {@link
|
<li>Все файлы, сохраненные во внешнем хранилище с использованием {@link
|
||||||
android.content.Context#getExternalFilesDir getExternalFilesDir()}.</li>
|
android.content.Context#getExternalFilesDir getExternalFilesDir()}.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Однако вам следует регулярно вручную очищать кэш-память, чтобы удалить файлы, созданные с помощью
|
<p>Однако вам следует регулярно вручную очищать кэш-память, чтобы удалить файлы, созданные с помощью
|
||||||
{@link android.content.Context#getCacheDir()}, а также удалять любые
|
{@link android.content.Context#getCacheDir()}, а также удалять любые
|
||||||
другие ненужные файлы.</p>
|
другие ненужные файлы.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,7 +250,7 @@ public boolean isExternalStorageReadable() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>例如,您的应用下载的其他资源或临时介质文件。</p>
|
<p>例如,您的应用下载的其他资源或临时介质文件。</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES}。
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ android.content.Context#getExternalFilesDir getExternalFilesDir()} 获取相应
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -311,7 +311,7 @@ getExternalStoragePublicDirectory()}。
|
|||||||
|
|
||||||
<p>无论您对于共享的文件使用 {@link
|
<p>无论您对于共享的文件使用 {@link
|
||||||
android.os.Environment#getExternalStoragePublicDirectory
|
android.os.Environment#getExternalStoragePublicDirectory
|
||||||
getExternalStoragePublicDirectory()} 还是对您的应用专用文件使用
|
getExternalStoragePublicDirectory()} 还是对您的应用专用文件使用
|
||||||
{@link android.content.Context#getExternalFilesDir
|
{@link android.content.Context#getExternalFilesDir
|
||||||
getExternalFilesDir()} ,您使用诸如
|
getExternalFilesDir()} ,您使用诸如
|
||||||
{@link android.os.Environment#DIRECTORY_PICTURES} 的 API 常数提供的目录名称非常重要。
|
{@link android.os.Environment#DIRECTORY_PICTURES} 的 API 常数提供的目录名称非常重要。
|
||||||
@@ -332,7 +332,7 @@ java.io.IOException} 。
|
|||||||
此信息也可用来避免填充存储卷以致超出特定阈值。
|
此信息也可用来避免填充存储卷以致超出特定阈值。
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>但是,系统并不保证您可以写入与 {@link java.io.File#getFreeSpace}
|
<p>但是,系统并不保证您可以写入与 {@link java.io.File#getFreeSpace}
|
||||||
指示的一样多的字节。如果返回的数字比您要保存的数据大小大出几 MB,或如果文件系统所占空间不到 90%,则可安全继续操作。否则,您可能不应写入存储。
|
指示的一样多的字节。如果返回的数字比您要保存的数据大小大出几 MB,或如果文件系统所占空间不到 90%,则可安全继续操作。否则,您可能不应写入存储。
|
||||||
|
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>注意:</strong>当用户卸载您的应用时,Android 系统会删除以下各项:
|
<p><strong>注意:</strong>当用户卸载您的应用时,Android 系统会删除以下各项:
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>您保存在内部存储中的所有文件</li>
|
<li>您保存在内部存储中的所有文件</li>
|
||||||
<li>您使用 {@link
|
<li>您使用 {@link
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ API 讀取並寫入檔案。
|
|||||||
該物件的用途很廣,例如非常適用於影像檔案或透過網路交換的項目。
|
該物件的用途很廣,例如非常適用於影像檔案或透過網路交換的項目。
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>本課程將顯示如何在您的應用程式中執行與檔案相關的基本任務。本課程假設您已熟悉 Linux 檔案系統的基本概念,以及
|
<p>本課程將顯示如何在您的應用程式中執行與檔案相關的基本任務。本課程假設您已熟悉 Linux 檔案系統的基本概念,以及
|
||||||
{@link java.io} 中的標準檔案輸入/輸出 API。
|
{@link java.io} 中的標準檔案輸入/輸出 API。
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -250,12 +250,12 @@ public boolean isExternalStorageReadable() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>例如,您的應用程式下載的附加資源,或暫存媒體檔案都是私用檔案。</p>
|
<p>例如,您的應用程式下載的附加資源,或暫存媒體檔案都是私用檔案。</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<p>若您希望將公用檔案儲存在外部儲存空間,請使用
|
<p>若您希望將公用檔案儲存在外部儲存空間,請使用
|
||||||
{@link android.os.Environment#getExternalStoragePublicDirectory
|
{@link android.os.Environment#getExternalStoragePublicDirectory
|
||||||
getExternalStoragePublicDirectory()} 方法取得代表外部儲存空間內相應目錄的 {@link java.io.File}。
|
getExternalStoragePublicDirectory()} 方法取得代表外部儲存空間內相應目錄的 {@link java.io.File}。
|
||||||
該方法採用對要儲存的檔案類型進行指定 (以便能合理區分這些檔案與其他公用檔案) 的引數,諸如 {@link android.os.Environment#DIRECTORY_MUSIC} 或 {@link
|
該方法採用對要儲存的檔案類型進行指定 (以便能合理區分這些檔案與其他公用檔案) 的引數,諸如 {@link android.os.Environment#DIRECTORY_MUSIC} 或 {@link
|
||||||
@@ -265,7 +265,7 @@ android.os.Environment#DIRECTORY_PICTURES}。
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -287,7 +287,7 @@ android.content.Context#getExternalFilesDir getExternalFilesDir()},然後向
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -366,7 +366,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>注意:</strong>使用者解除安裝您的應用程式時,Android 系統會刪除以下檔案:
|
<p><strong>注意:</strong>使用者解除安裝您的應用程式時,Android 系統會刪除以下檔案:
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>您在內部儲存空間儲存的所有檔案</li>
|
<li>您在內部儲存空間儲存的所有檔案</li>
|
||||||
<li>您使用 {@link
|
<li>您使用 {@link
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ public File getTempFile(Context context, String url) {
|
|||||||
try {
|
try {
|
||||||
String fileName = Uri.parse(url).getLastPathSegment();
|
String fileName = Uri.parse(url).getLastPathSegment();
|
||||||
file = File.createTempFile(fileName, null, context.getCacheDir());
|
file = File.createTempFile(fileName, null, context.getCacheDir());
|
||||||
catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Error while creating file
|
// Error while creating file
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -259,7 +259,7 @@ these files should remain available to the user.
|
|||||||
your app. Although these files are technically accessible by the user and other apps because they
|
your app. Although these files are technically accessible by the user and other apps because they
|
||||||
are on the external storage, they are files that realistically don't provide value to the user
|
are on the external storage, they are files that realistically don't provide value to the user
|
||||||
outside your app. When the user uninstalls your app, the system deletes
|
outside your app. When the user uninstalls your app, the system deletes
|
||||||
all files in your app's external private directory.
|
all files in your app's external private directory.
|
||||||
<p>For example, additional resources downloaded by your app or temporary media files.</p>
|
<p>For example, additional resources downloaded by your app or temporary media files.</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
@@ -274,7 +274,7 @@ android.os.Environment#DIRECTORY_PICTURES}. For example:</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(String albumName) {
|
public File getAlbumStorageDir(String albumName) {
|
||||||
// Get the directory for the user's public pictures directory.
|
// Get the directory for the user's public pictures directory.
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory(
|
File file = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -296,7 +296,7 @@ user uninstalls your app.</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
public File getAlbumStorageDir(Context context, String albumName) {
|
public File getAlbumStorageDir(Context context, String albumName) {
|
||||||
// Get the directory for the app's private pictures directory.
|
// Get the directory for the app's private pictures directory.
|
||||||
File file = new File(context.getExternalFilesDir(
|
File file = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_PICTURES), albumName);
|
Environment.DIRECTORY_PICTURES), albumName);
|
||||||
if (!file.mkdirs()) {
|
if (!file.mkdirs()) {
|
||||||
@@ -375,7 +375,7 @@ myContext.deleteFile(fileName);
|
|||||||
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p><strong>Note:</strong> When the user uninstalls your app, the Android system deletes
|
<p><strong>Note:</strong> When the user uninstalls your app, the Android system deletes
|
||||||
the following:</p>
|
the following:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>All files you saved on internal storage</li>
|
<li>All files you saved on internal storage</li>
|
||||||
<li>All files you saved on external storage using {@link
|
<li>All files you saved on external storage using {@link
|
||||||
|
|||||||
Reference in New Issue
Block a user