*
The moose likes Mac OS and the fly likes MAC OS X path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "MAC OS X path" Watch "MAC OS X path" New topic
Author

MAC OS X path

Abder-Rahman Ali
Ranch Hand

Joined: May 22, 2008
Posts: 138
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

That greatly depends upon where the file is in the file system.

So, where is it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abder-Rahman Ali
Ranch Hand

Joined: May 22, 2008
Posts: 138
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Jan 10, 2002
Posts: 60810
    
  65

And remember, this isn't Windows. Case counts!
Abder-Rahman Ali
Ranch Hand

Joined: May 22, 2008
Posts: 138
Bear Bibeault wrote:And remember, this isn't Windows. Case counts!


Thank you very much.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Also note that Windows is perfectly happy with forward slashes:

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

works just fine.


[Jess in Action][AskingGoodQuestions]
Bill Tubbs
Greenhorn

Joined: Sep 22, 2012
Posts: 3
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

Why the "file://localhost" prefix?
Bill Tubbs
Greenhorn

Joined: Sep 22, 2012
Posts: 3

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




Thanks.
Bill Tubbs
Greenhorn

Joined: Sep 22, 2012
Posts: 3
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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MAC OS X path
 
Similar Threads
Class.getMethod with variable args - part 2
Applet security permission on MAC OS?
Working directory question
MAC OS X path
Next kitty will be ...