• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

getResourceAsStream on the Mac

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to the Mac. I am trying to port some Java applications to my iBook.

However, no matter what I try, I am unable to get getResourceAsStream() to work.


Any tips would be greatly appreciated!
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never had an issue with it. It might help if you could be more explicit about what "unable to work" means.
 
David Leangen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I mean that no matter what I try, it keeps returning null. With exactly the same code I have no problem on either a Win or a Linux system. I can't figure out how it works on the Mac and why it would be different.

Essentially, I have a "configuration" file for a class. For instance, if I have com.company.SomeClass, and bundled with it I have com.company.SomeClass.config, I am making a call such as:

SomeClass sc = new SomeClass();
InputStream is = sc.getClass().getResourceAsStream("/com/company/SomeClass.config");


Also tried the same thing in virtually every combination I could think of (using ClassLoader.getResourceAsStream, using the Mac file separator, omitting the leading slash... )


Any tips would be greatly appreciated!
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm at a loss as to why it doesn't work on a Mac, but have you tried this:



Just a thought...
 
David Leangen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted a follow up here:

http://lists.ibiblio.org/pipermail/support-dpml/2005q1/000609.html


Cheers,
Dave
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From that link, it looks like you are working with the old MacOS (9-), rather than OS X? The reason I conclude that is that the file separator on the old MacOS is ":", but on OS X it is "/" just like any other Unix. The JVM on the old MacOS is ancient, so I'm not surprised it doesn't support reflection well.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Warren, I think you'll find that the separator in OS X is still ":", and that's what Dave is getting at in the posted follow-up.
[ April 08, 2005: Message edited by: Ben Poole ]
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that there may be confusion about what separator is being talked about.

/ is the folder separator, as in /usr/local/tomcat5

: is the path separator, as you would use in the classpath to separate the component folders
 
Ben Poole
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
I think that there may be confusion about what separator is being talked about.


Indeed, my apologies for my part in that. Returning to the issue at hand, I believe Dave has found a work-around, per his linked post. He says,

The Mac does not use the Sun implementation. I have no idea who makes it...
Anyway, it doesn't work the same way.


Well, I can at least answer this one: Sun don't provide a Java implementation for OS X: they leave it to Apple. So I guess it's Apple who are responsible in this instance. I don't imagine for a minute they're going to provide more detail on how the classloader works, but you never know...
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!