初始化File对象 [英] Initialization of a File object
本文介绍了初始化File对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一下Java初始化的格式.
I want to ask you about the format of initialization in java.
我目前所知道的是:
int a = 1;
double b = 1.0;
String c = "java";
等
现在,在主类中,我想初始化一个 File
,而我不知道该怎么做?
Now, in the class main I want to initialize a File
, and I don't know how to do this?
推荐答案
首先,文件是对象类型,与int和double不同,它们是原始类型.我不确定您对Java有多熟悉,但是要创建一个对象,请使用该对象的构造函数.
Firstly, a file is an object type, unlike int and double, which are primitive types. I am not sure how familiar you are with java, but to create an object you use the constructor for that object.
文件具有一个构造函数,该构造函数接收该文件在计算机上的位置字符串.
File has a constructor which receives a string of the location of that file on the computer.
File f = new File("path\\to\\your\\file");
这篇关于初始化File对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文