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

java program for linux

 
Joseph Bashir
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please tell me how to write a file's path for linux in java. We write for windows as

File file = new File("D:\\testdir\\testfile.txt");

How can we write this path if we are on linux.

Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In UNIX there is no drive letter as there is in DOS. There is only "root", which is the lowest level of the file structure. Also, in UNIX, the path separator is a forward slash instead of a backslash. Your path, then, would look like this:

/testdir/testfile.txt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic