프로젝트의 기본 폴더에서 config.properties 파일을로드하는 기능이 있습니다. 그러나 FileNotFoundException을 제공하고 이유를 모르겠습니다. 내 방법은 다음과 같습니다프로젝트 폴더에 파일이 없습니다.
public static Configfile configuration() {
String server = null;
int dbport = 0;
String dbuser = null;
String dbpass = null;
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
prop.load(input);
server = prop.getProperty("server");
dbport = Integer.parseInt(prop.getProperty("dbport"));
dbuser = prop.getProperty("dbuser");
dbpass = prop.getProperty("dbpassword");
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return new Configfile(server, dbport, dbuser, dbpass);
}
그리고 내 config.properties 파일에 있습니다
E : \ 안드로이드 \ NSomething5
나는 무엇을 놓치고?
편집 : 스택 트레이스 :
유효한 안드로이드 파일 시스템 경로를하지12-04 17:00:07.619: W/System.err(21368): java.io.FileNotFoundException: /config.properties: open failed: ENOENT (No such file or directory)
12-04 17:00:07.619: W/System.err(21368): at libcore.io.IoBridge.open(IoBridge.java:416)
12-04 17:00:07.619: W/System.err(21368): at java.io.FileInputStream.<init>(FileInputStream.java:78)
12-04 17:00:07.619: W/System.err(21368): at java.io.FileInputStream.<init>(FileInputStream.java:105)
12-04 17:00:07.619: W/System.err(21368): at com.example.nsomething.utils.DBOperations.configuration(DBOperations.java:122)
12-04 17:00:07.619: W/System.err(21368): at com.example.nsomething.utils.DBOperations.<init>(DBOperations.java:24)
12-04 17:00:07.619: W/System.err(21368): at com.example.nsomething.Report.<init>(Report.java:20)
12-04 17:00:07.619: W/System.err(21368): at java.lang.Class.newInstanceImpl(Native Method)
12-04 17:00:07.619: W/System.err(21368): at java.lang.Class.newInstance(Class.java:1319)
12-04 17:00:07.619: W/System.err(21368): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
12-04 17:00:07.619: W/System.err(21368): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
12-04 17:00:07.619: W/System.err(21368): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
12-04 17:00:07.619: W/System.err(21368): at android.app.ActivityThread.access$700(ActivityThread.java:150)
12-04 17:00:07.619: W/System.err(21368): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
12-04 17:00:07.619: W/System.err(21368): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 17:00:07.619: W/System.err(21368): at android.os.Looper.loop(Looper.java:137)
12-04 17:00:07.619: W/System.err(21368): at android.app.ActivityThread.main(ActivityThread.java:5279)
12-04 17:00:07.619: W/System.err(21368): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 17:00:07.619: W/System.err(21368): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 17:00:07.619: W/System.err(21368): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
12-04 17:00:07.619: W/System.err(21368): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
12-04 17:00:07.619: W/System.err(21368): at dalvik.system.NativeStart.main(Native Method)
12-04 17:00:07.619: W/System.err(21368): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
12-04 17:00:07.619: W/System.err(21368): at libcore.io.Posix.open(Native Method)
12-04 17:00:07.619: W/System.err(21368): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
12-04 17:00:07.619: W/System.err(21368): at libcore.io.IoBridge.open(IoBridge.java:400)
12-04 17:00:07.619: W/System.err(21368): ... 20 more
'함수의 메인 폴더에있는 파일'?? 죄송합니다. 함수에 폴더가 있다는 것을 알지 못합니다. 설명 해주십시오. – greenapps
이 코드를 어디에서 실행하고 있습니까? –
Java 7을 사용하는 경우 try-with-resources 및 java.nio.file을 사용하십시오. 'FileNotFoundException'은 쓸모가 없습니다. – fge