private String readFile(){
try {
System.out.println("打开文件"); FileInputStream fileInputStream=openFileInput("/sdcard/sd.txt");//这里有错?
System.out.println("打开成功");//运行不到这里
byte[] buffer=new byte[fileInputStream.available()];
System.out.println("开始读取");
fileInputStream.read(buffer);
System.out.println("读取完成");
fileInputStream.close();
return new String(buffer,"GBK");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我的sdcard目录如下:
+data
-sdcard
+LOST.DIR
sd.txt
+system
try {
System.out.println("打开文件"); FileInputStream fileInputStream=openFileInput("/sdcard/sd.txt");//这里有错?
System.out.println("打开成功");//运行不到这里
byte[] buffer=new byte[fileInputStream.available()];
System.out.println("开始读取");
fileInputStream.read(buffer);
System.out.println("读取完成");
fileInputStream.close();
return new String(buffer,"GBK");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我的sdcard目录如下:
+data
-sdcard
+LOST.DIR
sd.txt
+system
-sdcard
+LOST.DIR
sd.txt
+system
具体是怎样的???文件是放在sdcard/下的,
FileInputStream fileInputStream=openFileInput(SDFile.getAbsolutePath() + File.separator + "sd.txt");冒是也不行
Since: API Level 1
Open a private file associated with this Context's application package for reading.Parameters
name The name of the file to open; can not contain path separators.
Returns
FileInputStream Resulting input stream.
Throws
FileNotFoundException
访问sdcard原来这样:
FileInputStream fileInputStream=new FileInputStream("/sdcard/sd.txt");
谢谢,各位!
FileInputStream fput = new FileInputStream(file);感觉这样好些