如何在 Ubuntu 中检查 Java 中的 isFile() 或 isDirectory() 函数?

编程入门 行业动态 更新时间:2024-10-25 03:22:38
本文介绍了如何在 Ubuntu 中检查 Java 中的 isFile() 或 isDirectory() 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 ubuntu 中,isFile()isDirectory() 不能完美运行.我使用此代码来确定某些内容是文件还是目录:

In ubuntu, isFile() and isDirectory() don't work perfectly. I used this code to find out if something is a file or directory:

boolean fileName= file.getName().lastIndexOf('.') == -1;

但问题是我创建了一个名为 bhargav.panchal 的文件夹.有了上面的功能,这个文件夹就被认为是一个文件,而不是一个文件夹.

But the problem is that I made a folder named bhargav.panchal. With the above function, this folder is considered as a file, not a folder.

File file=new File("/home/asd/My_Shared_File/bhargav.panchal");

if(file.exists()){
    if(!file.isDirectory()) {
        Toast.makeText(activity, "This is File", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(activity, "This is Directory", Toast.LENGTH_SHORT).show();
    }
} else {
    Toast.makeText(activity, "File or Directory doesn't exist.", Toast.LENGTH_SHORT).show();
}

在这种情况下,isDirectory()isFile() 方法总是返回 false.

In this condition, the isDirectory() and isFile() methods always return false.

推荐答案

不,你有什么地方错了.相反,您无法使用 DVM 访问外部环境.

No, you are wrong somewhere. On the contrary you cant access external environment with DVM.

原因:基于操作系统级别的应用程序之间不可能相互干扰安全性和 Dalvik 虚拟机仅限于单个操作系统进程,Dalvik 本身并不关心运行时安全.尽管 Dalvik 不依赖于安全性,但有趣的是,大多数的标准 Java 安全类保留在 Android 发行版中.这些包括java.lang.SecurityManager 和 java.security 包中的一些类.在标准 Java 中环境中,SecurityManger 的作用类似于操作系统进程级安全性.安卓.SecurityManager 通常控制对 JVM 外部资源的访问,例如文件、进程和网络.在 Android 发行版中,标准的安全框架是显然存在于应用程序在其自己的应用程序空间 中使用但既不完全为进程间安全实现或配置(不存在 java.policy 文件).

reason : it is not possible for applications to interfere with each other based on the OS level security and Dalvik VMs are confined to a single OS process, Dalvik itself is not concerned with runtime security. Although Dalvik is not relied upon for security, it is interesting to note that most of the standard Java security classes remain in the Android distribution. These include the java.lang.SecurityManager and some of the classes in the java.security package. In standard Java environments, the SecurityManger plays the role analogous to the OS process-level security in Android. The SecurityManager typically controls access to resources external to the JVM such as files, processes, and the network. In the Android distribution, the standard security framework is apparently present for applications to use within their own application space but is neither fully implemented nor configured (no java.policy files are present) for interprocess security.

这篇关于如何在 Ubuntu 中检查 Java 中的 isFile() 或 isDirectory() 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 07:36:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   如何在   Ubuntu   Java   isFile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!