mirror of
https://github.com/corda/corda.git
synced 2025-06-16 22:28:15 +00:00
add listFiles and isFile methods to java.io.File
This commit is contained in:
@ -305,6 +305,21 @@ Java_java_io_File_isDirectory(JNIEnv* e, jclass, jstring path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jboolean JNICALL
|
||||||
|
Java_java_io_File_isFile(JNIEnv* e, jclass, jstring path)
|
||||||
|
{
|
||||||
|
const char* chars = e->GetStringUTFChars(path, 0);
|
||||||
|
if (chars) {
|
||||||
|
STRUCT_STAT s;
|
||||||
|
int r = STAT(chars, &s);
|
||||||
|
bool v = (r == 0 and S_ISREG(s.st_mode));
|
||||||
|
e->ReleaseStringUTFChars(path, chars);
|
||||||
|
return v;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT jboolean JNICALL
|
extern "C" JNIEXPORT jboolean JNICALL
|
||||||
Java_java_io_File_exists(JNIEnv* e, jclass, jstring path)
|
Java_java_io_File_exists(JNIEnv* e, jclass, jstring path)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,12 @@ public class File {
|
|||||||
return isDirectory(path);
|
return isDirectory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static native boolean isFile(String path);
|
||||||
|
|
||||||
|
public boolean isFile() {
|
||||||
|
return isFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
int index = path.lastIndexOf(FileSeparator);
|
int index = path.lastIndexOf(FileSeparator);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
@ -141,6 +147,19 @@ public class File {
|
|||||||
return mkdir();
|
return mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File[] listFiles() {
|
||||||
|
return listFiles(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File[] listFiles(FilenameFilter filter) {
|
||||||
|
String[] list = list(filter);
|
||||||
|
File[] result = new File[list.length];
|
||||||
|
for (int i = 0; i < list.length; ++i) {
|
||||||
|
result[i] = new File(this, list[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] list() {
|
public String[] list() {
|
||||||
return list(null);
|
return list(null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user