package com.test.methods;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import android.R;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.crumbin.main.R.color;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class JsonParserActivity extends Activity {
String strLine = null;
String[] values = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.main.R.layout.user_main);
// Open the file that is the first
// command line parameter
try {
FileInputStream fstream = new FileInputStream("/home/hic/jdata.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
//Read File Line By Line
while ((br.readLine()) != null) {
// Print the content on the console
strLine = strLine + br.readLine();
}
this.parse(strLine);
//Close the input stream
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
parse(strLine);
ListView contactLV = (ListView) findViewById(com.crumbin.main.R.id.user_contact_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,com.main.R.layout.user_contact_list_item,com.main.R.id.contact_name,values);
contactLV.setAdapter(adapter);
}
public void parse(String jsonLine) {
JsonElement jelement = new JsonParser().parse(jsonLine);
JsonObject jobject = jelement.getAsJsonObject();
JsonArray jarray = jobject.getAsJsonArray("contact");
jobject = jarray.get(0).getAsJsonObject();
values[0]= jobject.get("user").toString();
}
}
我已尝试过file.CanRead()和file.exist(),并且都返回False。该文件存在。此外,任何其他进程都不会读取该文件。
答案 0 :(得分:3)
如果canRead
不起作用且文件确实存在,则表示存在权限问题。
答案 1 :(得分:2)
如果canRead()和exists()返回false,即使该文件实际存在,则表示该应用程序对该文件/文件夹没有读取权限...