FileInputStream fis = new FileInputStream("./abc.txt");
I wa开发者_Go百科nt to replace the quoted value by a string
I also want to fill the string with different filenames in a switch statement so that I can open different files and perform repeated operations on the files data.
how do I go about this?
FileInputStream fis = new FileInputStream(filename);
Note that there is no String.valueOf(String)
. If there was, it would be pointless as it would likely just return the String
you passed it.
Note that Java doesn't support Strings
as case
parameters (or at least you'll have to wait for Java 7 to do so), so you'll need a set of if
/else
comparisons to do different things for different filenames.
if ("a.txt".equals(filename)) {
// do something
}
if ("b.txt".equals(filename)) {
// do something
}
etc.
精彩评论