我希望我的应用程序检查文件的最后修改日期并阅读它,但它的行为就像文件不存在,即使我知道它在那里。这是我的代码:
File f = new File("data/system/dropbox/data_app_crash@1528276030506.txt");
if(f.exists() && !f.isDirectory()) {
System.out.println("I see you");
}
System.out.println("Before Format : " + f.lastModified());
我的清单中有READ_INTERNAL_STORAGE和READ_LOGS权限,并且还通过adb(adb shell pm grant package android.permission)给出了它们,我也有root权限。
怎么办?
答案 0 :(得分:0)
您应该将代码更改为以下内容并使用import { Injectable } from "@angular/core";
import { Subject } from "rxjs";
@Injectable()
export class InfinityScrollFeedService {
dataPackages = [];
someMokeNames = ["Hari", "Xapu", "Hristiyan", "Pesho", "Gosho", "Ivan"];
httpCallMocker = <[]>new Subject();
constructor() {}
private getRandomNumber = max => {
return Math.floor(Math.random() * Math.floor(max));
};
private addDataPackage = () => {
let newData = [];
for (let i = 0; i < 10; i++) {
newData.push({
name: this.someMokeNames[
this.getRandomNumber(this.someMokeNames.length - 1)
],
age: this.getRandomNumber(100)
});
}
this.dataPackages.push(newData);
};
retrivePackage(page) {
if (this.dataPackages.length <= page) {
this.addDataPackage();
}
this.httpCallMocker.next(this.dataPackages[page]);
}
}
方法
getFileStreamPath
或 File file = context.getFileStreamPath(filename);
if(file == null || !file.exists()) {
// Do something
}else{
// Do something else
}
方法
openFileInput