Android现学现用第六天
图片存进去了,可正在实验怎么读出来~
这个博客不错,关于bitmap的 http://blog.csdn.net/pathuang68/article/details/4219681
我在考虑。。。是不是把图片保存到本地文件夹更好一些。。。。
ok
保存到sd卡上了,问题是开始时存进去读不出来~
原来时路径找不到
存:
public void saveMyBitmap(String bitName) throws IOException {
File f = new File("/sdcard/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
b.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
读取:
//String imagepath = Environment.getExternalStorageDirectory() + "/sdcard/1.png";
注视掉的这一行就是错误的读取方法
bmpout = BitmapFactory.decodeFile("/sdcard/1.png");
iv = (ImageView)findViewById(R.id.image_view_in_search);
iv.setImageBitmap(bmpout);
在SD卡上创建文件夹并保存txt文件进去:
public void put(String itemName,String address,String comment,String autoposition)
{
try
{
String path="/sdcard/cardImages";
File pathFile = new File(path);
if (!pathFile.exists()) {
//若不存在,创建目录,可以在应用启动的时候创建
pathFile.mkdirs();
}
FileOutputStream outStream = new FileOutputStream("/sdcard/cardImages/details.txt",true);
OutputStreamWriter writer = new OutputStreamWriter(outStream,"gb2312");
writer.write(itemName);
writer.write("\n");
writer.flush();
writer.close();//记得关闭
outStream.close();
}
catch (Exception e)
{
Log.e("m", "file write error");
}
}
读取SD卡上的txt
File f=null;
f= new File("/sdcard/cardImages/details.txt");//这是对应文件名
InputStream in = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
in = new BufferedInputStream(fis);
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in, "gb2312"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String tmp;
try {
while((tmp=br.readLine())!=null){
//在这对tmp操作
setTitle(tmp);
}
br.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
今天的战斗成果:上传页面中
搜索页面中
posted on 2011-09-06 11:58 Wind Runner 阅读(148) 评论(0) 编辑 收藏 举报