Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

especial characters

 
Fernando Dominguez
Ranch Hand
Posts: 106
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I would like to get a String value will be ="C:\file.txt";

DocumentacionCategoriaDto documentacionCategoriaDto= documentacionCategoriaModel.getDocumento(idDocumento);
ruta = documentacionCategoriaDto.getRutaDoc() + "\\" + documentacionCategoriaDto.getNombreDoc();
System.out.println(ruta);

By this way compiler doesn't complain

System.out shows C:\file.txt

But debbuger says that ruta's value is "c:\\file.txt"
if I only use "\" eclipse complains.

Howe can I get C:\file.txt

Thanks
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certain charactors in a string have special meaning, and are called escape charactors, to create these escape charactors a \ is used thus, if you wish to use \ in a string you most escape it, making: \\

thus c:\\file.txt will be printed on screen as c:\file.txt

you could also try using unix like seprators ie c:/file.txt

[ June 19, 2007: Message edited by: Gavin Tranter ]
[ June 19, 2007: Message edited by: Gavin Tranter ]
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the problem with your solution, but you could also try:

[ June 19, 2007: Message edited by: Sasha Ruehmkorf ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic