1
 FileInputStream fis = new FileInputStream("./abc.txt");

I want 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?

2 Answers 2

4
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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.