gpt4 book ai didi

Java FileNotFoundException 尽管文件存在。

转载 作者:行者123 更新时间:2023-12-01 17:33:13 24 4
gpt4 key购买 nike

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。该文件存在。此外,该文件没有被任何其他进程读取。

最佳答案

如果canRead不起作用并且文件确实存在,则意味着存在权限问题。

关于Java FileNotFoundException 尽管文件存在。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9017392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com