Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MAC OS X path

 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, when I'm on a Windows machine, I write the following:

File f= new File("C:\\SomeFile.doc");

How can I write the file path at MAC OS X?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends upon where the file is in the file system.

So, where is it?
 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:That greatly depends upon where the file is in the file system.

So, where is it?


On the Desktop
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file path to a file named somefile.txt on the user's Desktop, assuming the user is named bear would be:

/Users/bear/Desktop/somefile.txt


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And remember, this isn't Windows. Case counts!
 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And remember, this isn't Windows. Case counts!


Thank you very much.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that Windows is perfectly happy with forward slashes:

File f= new File("C:/SomeFile.doc");

works just fine.
 
Bill Tubbs
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is helpful thanks. I am also trying to read a file from a Mac OS X filesystem using C++.

I get the user to select the file location using the NSOpenPanel method and convert the URL to a const char inputFilename which looks something like this:

file://localhost/Users/.../DataFile.txt

But when I try to open the file with



inFile.is_open() returns an error.

Do I need to manipulate this path before using it in ifstream?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the "file://localhost" prefix?
 
Bill Tubbs
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't know. I didn't add it. That's what NSOpenPanel returned:




Thanks.
 
Bill Tubbs
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault.

I think I've found the problem. I was using the wrong class method [fileURL absoluteString].

I should be using path. "Returns the path of a URL conforming to RFC 1808."

See http://stackoverflow.com/questions/3057086/how-to-chop-off-file-from-nsurl

Sorry to those who are not familiar with ObjectiveC.

Thanks!
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:Also note that Windows is perfectly happy with forward slashes:
File f= new File("C:/SomeFile.doc");


But that is because the JVM handles both backwards and forward slashes. Its a runtime thing.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill Tubbs wrote:This is helpful thanks. I am also trying to read a file from a Mac OS X filesystem using C++.


From your code samples, it looks to me as if you are using Objective C. That is a separate language, not the same as C++.

Being specific about what you are doing and which tools you are using makes it easier for us to help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic