PDA

View Full Version : File Input in Java

thefil
Jul 26, 2007, 10:31 AM
I'm coming from a Windows environment and I have a bit of a file input problem...

glass = new Scanner( new File("\Users\filipkrynicki\Mydia 4.0\build\classes\mydia40\db.m4"));

returns an error "illegal escape character"

*edit* I fixed that problem by doubling the \\s, but now it can't find the file. Am I doing something wrong?

itickings
Jul 26, 2007, 11:01 AM
My guess would be the use of \ instead of /.

To avoid this kind of problem, consider using File.separator (http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#separatorChar) instead of assuming a specific separator.