导航:首页 > 操作系统 > android访问本地文件的文件

android访问本地文件的文件

发布时间:2022-08-29 14:42:43

android 中如果我想访问本地文件e:\test.txt,要如何赋值String test="http://10.0.2.2:8080" 后面加什么

你是想读取手机sdcard里的文件还是远端服务器上的文件。如果是sdcard上的文件,知道文件的路径就可以调用函数进行读取了,如果是远端服务器上的,你得写一个项目放到服务器下让手机通过网络来获取。

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

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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>

代码

java">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();
/* 开启Pictures画面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 使用URL获取本地的文件

public String getFromAssets(String fileName){
try {
InputStreamReader inputReader = new InputStreamReader( getResources().getAssets().open(fileName) );
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
String Result="";
while((line = bufReader.readLine()) != null)
Result += line;
return Result;
} catch (Exception e) {
e.printStackTrace();
}
}

④ Android: 如何访问项目文件夹下的文件

Android中读取assets文件夹里面的文件,可使用SDK的API,需要用AssetManager以字节流的形式读取文件。
assets的读取方式:
1. 先在Activity里面调用getAssets() 来获取AssetManager引用。
2. 再用AssetManager的open(String fileName, int accessMode) 方法则指定读取的文件以及访问模式就能得到输入流InputStream。
3. 然后就是用已经open file 的inputStream读取文件,读取完成后记得inputStream.close() 。
4.调用AssetManager.close() 关闭AssetManager。
需要注意的是,来自Resources和Assets 中的文件只可以读取而不能进行写的操作。

⑤ 如何用android手机访问电脑上的文件

那必须要处于同一局域网内。
譬如你有无线路由器,电脑和手机用的都是这个路由器的网络。
然后手机上下载ES文件浏览器,同时把电脑上想要访问的文件夹设置为共享状态,手机可以通过ES文件浏览器来访问电脑上的文件了。
另外在局域网内,可以通过teamviewer远程控制电脑,当然,手机和电脑要同时安装teamviewer的客户端,免费的。

⑥ Android如何访问本地的数据库

你可以选择使用文件管理器。如果你是4.0以上的,应该可以不用软件,自带。不过,我可以给你推荐一个软件,它又是管家,也可以看文件,LBE安全大师,真的很好用。

阅读全文

与android访问本地文件的文件相关的资料

热点内容
服务器如何搭建多个节点 浏览:324
acx算法 浏览:254
幽冥诡匠漫画全集用什么app可以看 浏览:1001
租用服务器为什么越来越慢 浏览:960
算法创新就业方向 浏览:423
算法最优解作者 浏览:867
通达信红绿宝塔线指标源码 浏览:666
app是什么东西合法吗 浏览:231
怎么锁app视频教程 浏览:841
迅捷pdf注册码生成器 浏览:748
androidsdkosx 浏览:302
压缩面膜纸荧光 浏览:841
app怎么分身三个 浏览:744
电影bt下载源码 浏览:421
iwatch屏幕加密芯片 浏览:570
公安主题网站源码 浏览:986
天津市服务器供应商云服务器 浏览:115
数控车床子程序编程 浏览:111
floydwarshall算法 浏览:717
丢失微信app怎么找 浏览:252