Java: isBinary 方法的类是什么?
我习惯了 java.io.* 和 java.util.* 但不习惯树:
com.starbase.util
Class FileUtils
java.lang.Object
|
+--com.starbase.util.FileUtils
那么我应该导入哪个类才能使用 isBinary 方法?我是否执行“import java.lang.Object;”或“导入java.lang.Object.com.starbase.util.FileUtils;”?
I am accustomed to java.io.* and java.util.* but not to the tree:
com.starbase.util
Class FileUtils
java.lang.Object
|
+--com.starbase.util.FileUtils
So which class should I import to use the isBinary-method? Do I do "import java.lang.Object;" or "import java.lang.Object.com.starbase.util.FileUtils;"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以
import com.starbase.util.FileUtils;
或import static com.starbase.util.FileUtils.*
。层次结构仅显示类FileUtils
扩展了Object
(与所有类一样)。您还必须拥有 .jar 文件/API 才能访问此类。
编辑:添加了可能的独立实现:
如果您想自己实现这一点(我注意到您自己的“琐碎”答案),您可以执行以下操作:
请注意,我尚未对此进行测试。
我应该补充一点,这是一个简单的实现。有很多种文本文件都可以被视为二进制文件。如果您允许文本采用 Unicode 和/或 UTF-8(或其他文本编码),那么这很快就会变得非常困难。然后您需要开发某种启发式方法来区分不同类型的文件,但这并不是 100% 准确。所以,这实际上取决于你想用它做什么。
You would do
import com.starbase.util.FileUtils;
orimport static com.starbase.util.FileUtils.*
. The hierarchy is just showing that the classFileUtils
extendsObject
(as do all classes).You do also have to have the .jar file/API to access this class.
EDIT: Added possible standalone implementation:
If you want to implement this yourself (I noticed your own 'trivial' answer), you could do something like this:
Please note, I have not tested this.
I should add that this is the trivial implementation. There are many kinds of text files that would be considered binary with this. If you were to allow text to be Unicode and/or UTF-8 (or other text encoding) then this quickly becomes very difficult. Then you need to develop some kinds of heuristics to differentiate between the kinds of files and this would not be 100% accurate. So, it really depends on what you are trying to do with this.
您永远不必导入 java.lang.Object,它是隐式导入的,并且是所有其他类派生自的类。当您导入另一个类时,您可以根据它所在的包来导入它。因此,对于您想要使用的类,它将是:
You never have to import java.lang.Object, it's imported implicitely and is the class that every other class is derived from. When you import another class, you import it based on the package it's in. So for the class you want to use it would be:
com.starbase.util.FileUtils
不在标准打包的 Java SDK 中,而是在 StarTeam SDK,您需要下载它才能使用FileUtils#isBinary
方法。安装后,您只需要添加:
但是,如果您不想使用第三方 SDK,请告诉我们
isBinary
对您有何帮助,我们可以找到标准的 Java 等效项。另请澄清,
import.java.lang.Object.com.starbase.util.FileUtils
不是有效的导入,您正在将两个不同的包连接在一起。它必须是
import java.lang.Object
或import com.starbase.util.FileUtils
。com.starbase.util.FileUtils
is not in the standard packaged Java SDK, but instead the StarTeam SDK which you would need to download in order to use theFileUtils#isBinary
method.Once installed, you would just need to add:
However, if you do not want to use a third-party SDK, let us know how
isBinary
would be helpful to you and we could find a standard Java equivalent.Also to clarify,
import.java.lang.Object.com.starbase.util.FileUtils
is not a valid import, you are concatenating two different packages together.It has to be either
import java.lang.Object
orimport com.starbase.util.FileUtils
.完全微不足道,也许最简单,但非常不可靠!
Totally trivial and perhaps easiest but very unreliable!