hi all, I've a small problem. I want to retrieve a filename from the user, and then pass it to a FileInputStream object. The problem is that the user will ofcourse type in the file name as being 'c:\dirA\dirAA\file.ext' or something similar, whilst the object expects double '\\' as seperators: new FileInputStream("c:\\dirA\\dirAA\\file.ext"); Now I can ofcourse write a loop to go through the code and change every single '\' into a double '\\', but I cant help feeling there must be an easier way.... anyone want to offer an idea? TIA, Maarten [ February 05, 2004: Message edited by: Maarten Vergouwen ]
The constructor does not want double backslashes in the argument. It's just that to embed a single backslash in a Java string literal, you have to write a double one. The actual string represented in this Java code new FileInputStream("c:\\dirA\\dirAA\\file.ext") only contains the characters "c:\dirA\dirAA\file.ext" You can check this, if you don't believe me, by running System.out.println("c:\\dirA\\dirAA\\file.ext".toCharArray().length) and you'll find that the printed number corresponds to the length of the string with the single backslashes. In any event, the problem you're imagining isn't a problem. Use the user's input as-is, and it will work just fine.