Re: Easy question but I can't seem to get it to work



Bjorn Abelli wrote:
"Kevin Ashton" wrote...

I tried typing

FileReader file = new FileReader(c:\javaread\"file.txt");

The path must be included inside the String.

FileReader file = new FileReader("c:\javaread\file.txt");

Backslashes need to be "escaped":

FileReader file = new FileReader("c:\\javaread\\file.txt");


/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php

Alternatively use forward slashes "c:/javaread/file.txt". Modern versions of Windows recognise the forward slash as a path separator, and it means you don't have to worry about escaping the backslash.

--
TechBookReport Java http://www.techbookreport.com/JavaIndex.html

.



Relevant Pages

  • Re: Opinion) Overuse of symbolic constants
    ... >> It's pretty much utterly beside the point whether the average Windows ... >> user knows that forward slash can be used as a path separator. ... makin' dern fools of ourselfs ... ...
    (comp.lang.c)
  • Re: Path Separator and Windows
    ... > ruby to use the correct path separator? ... internally uses the slash as path separator on all platforms. ...
    (comp.lang.ruby)
  • Re: ZIP: Writing binary file fails
    ... that the path separator is a forward slash. ... Perhaps I should define Zip::SEPARATOR='/' or just make sure to substitute all copies of ... Thomas ...
    (comp.lang.ruby)