文件管理 · 2022年8月11日

android本地文件|Android编程 打开本地文件 文件选择器

① android如何获取本地文件属性信息

通过主动的方式通知系统我们需要文件列表,要向系统发送广播

sendBroadcast(newIntent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse(“file://”+Environment.getExternalStorageDirectory())));

然后通过接收器获取系统文列表

{privatefinalstaticStringTAG=”MediaScannerReceiver”;@OverridepublicvoidonReceive(Contextcontext,Intentintent){Stringaction=intent.getAction();Uriuri=intent.getData();StringexternalStoragePath=Environment.getExternalStorageDirectory().getPath();if(action.equals(Intent.ACTION_BOOT_COMPLETED)){//scaninternalstoragescan(context,MediaProvider.INTERNAL_VOLUME);}else{if(uri.getScheme().equals(“file”)){//Stringpath=uri.getPath();if(action.equals(Intent.ACTION_MEDIA_MOUNTED)&&externalStoragePath.equals(path)){scan(context,MediaProvider.EXTERNAL_VOLUME);}elseif(action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)&&path!=null&&path.startsWith(externalStoragePath+”/”)){scanFile(context,path);}}}}privatevoidscan(Contextcontext,Stringvolume){Bundleargs=newBundle();args.putString(“volume”,volume);context.startService(newIntent(context,MediaScannerService.class).putExtras(args));}privatevoidscanFile(Contextcontext,Stringpath){Bundleargs=newBundle();args.putString(“filepath”,path);context.startService(newIntent(context,MediaScannerService.class).putExtras(args));}}

② android开发中怎样清除本地缓存文件夹

getCacheDir()能够得到当前项目的缓存地址在项目中经常会使用到WebView 控件,当加载html 页面时,会在/data/data/应用package 目录下生成database与cache 两个文件夹。请求的url 记录是保存在WebViewCache.db,而url 的内容是保存在WebViewCache 文件夹下打开关闭使用缓存,一共有五个种类//优先使用缓存:WebView.getSettings().setCacheMod(WebSettings.LOAD_CACHE_ELSE_NETWORK); //不使用缓存:WebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);在退出应用的时候加上如下代码File file = CacheManager.getCacheFileBaseDir(); if (file != null && file.exists() && file.isDirectory()) { for (File item : file.listFiles()) { item.delete(); } file.delete(); } context.deleteDatabase("WebView.db"); context.deleteDatabase("WebViewCache.db");

③ Android浏览器怎么打开本地html文件

在android自带浏览器中打开本地文件方法:在浏览器地址栏中输入file://路径如在sdcard中有01.html这个文件,想用android自带浏览器打开它,只要在地址栏中输入file://sdcard/01.html即可。支持中文名。

④ android本地文件的读写是不是配置文件的读写

不是,本地文件的读写是指手机内部文件(手机本身自带的文件或内存卡的文件)读写!你说的配置文件的读写可以理解成其中的一部分。而且android对不同文件的读取方式也有不同,如果是工程内的配置文件读写的话会有专门的api去读取,如果是工程外文件直接使用JAVA中FILE类加载手机路径进行读写!在读写时应该给该工程加上读写文件的权限!!!

⑤ Android浏览器如何打开本地html文件

android 浏览器 打开本地html文件的方法有些html文件放在本地磁盘和sdcard,如何用打开这个网页呢?这种应用在测试时非常有用。有2个方法:1.使用文件管理器如ES等,需要幸运的是你的文件管理器直接用浏览器打开。2.在浏览器输入地址访问本地磁盘和SD卡上的HTML,前部分content://com.android.htmlfileprovider是Provider的标准,后面是程序目录。比如sdcard的tesl.html直接在浏览器里输入content://com.android.htmlfileprovider/sdcard/test.html回车就可以看到网页了。在代码webView.loadUrl("content://com.android.htmlfileprovider/sdcard/test.html")如果是其它程序的私有html文件,这样做会失败。这是由于com.android.htmlfileprovider的权限不够,如果是重写一个私有的HtmlProvider位于同一个应用中,应该能解决问题。然后就参考了原来的com.android.htmlfileprovider 源代码,改写了下。问题解决了,使用私有的HTMLProvider,可以轻松的访问手机内存中,程序私有目录下的html文件。网上有例子,你可以搜索!

⑥ Android怎么搜索本地指定类型文件

第三方的commons-io jar包。使用FileUtils里面的listFiles方法

FileUtils.listFiles(sdRoot,newString[]{”.txt“},true)

⑦ android怎么加载本地html文件

1。获取资复源的输入流制资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“test.html”) 方法获取输入流。注意:如果资源文件是文本文件则需要考虑文件的编码和换行符。建议使用UTF-8和Unix换行符。2. WebView 加载assets目录下的html文件资源文件 sample.html 位于 $PROJECT_HOME/assets/ 目录下,可以通过以下代码WebView.loadUrl(“file:///android_asset/test.html”); 加载html文件。

⑧ Android本地存储的几种方式

Android 提供了5种方式存储数据: –使用SharedPreferences存储数据; –文件存储数据; –SQLite数据库存储数据; –使用ContentProvider存储数据; –网络存储数据; 先说下,Preference,File, DataBase这三种方式分别对应的目录是/data/data/Package Name/Shared_Pref, /data/data/Package Name/files, /data/data/Package Name/database 。 在Android中通常使用File存储方式是用 Context.openFileOutput(String fileName, int mode)和Context.openFileInput(String fileName)。 Context.openFileOutput(String fileName, int mode)生成的文件自动存储在/data/data/Package Name/files目录下,其全路径是/data/data/Pac

⑨ Android编程 打开本地文件 文件选择器

代码如下:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android" target="_blank">http://schemas.android.com/apk/res/android</a>" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/b01" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ImageView android:id="@+id/iv01" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>代码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 import java.io.FileNotFoundException; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class Lesson_01_Pic extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.b01); button.setText("选择图片"); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { Intent intent = new Intent(); /* 开启画面Type设定为image */ intent.setType("image/*"); /* 使用Intent.ACTION_GET_CONTENT这个Action */ intent.setAction(Intent.ACTION_GET_CONTENT); /* 取得相片后返回本画面 */ startActivityForResult(intent, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = data.getData(); Log.e("uri", uri.toString()); ContentResolver cr = this.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); ImageView imageView = (ImageView) findViewById(R.id.iv01); /* 将Bitmap设定到ImageView */ imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(),e); } } super.onActivityResult(requestCode, resultCode, data); } }

⑩ android获取本地文件名字

首先你的路径是否正确,第二查看是否有读权限(默认是有的)。除这两点无其他可能,遍历没区别。