lets say we have a string
String ss="file1";
now i want to create a variable (a file variable) and i want its name to be file1 which is the content of the string ss.

Recommended Answers

All 2 Replies

what do you mean by a variable? your String itself is a variable.
if you want to create a File object named after that String:

String ss = "file1";
File myFile = new File(ss);

slight remark: the above will just create a File variable, not an actual file on your harddrive.

if you wanted something like this:

String ss = "file1";
File file1 = new File(); 
// having the name of the variable based on the contents of ss

you can't do that. you cant dynamically create and set names of variables.

The names of variables are defined when you use the editor to type them in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.