N. Liraj N. Liraj - 14 days ago 5x
Java Question

Initialization in java

I want to ask you about the format of initialization in java.

What I know in the moment is:

int a = 1;

double a = 1.0;

String a= "java";


Now, in the class main I want to initialize a file, and I don't know how to do this?

Thank you in advance


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");