Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

different results from same method call

 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class with 2 methods, one to read a properties file and the other to read a text file. The methods are almost identical in this one point ...

InputStream input = EMailer.class.getResourceAsStream("recipients.txt");
InputStream input = EMailer.class.getResourceAsStream("email.properties");

recipients.txt and email.properties are in the same directory.

Getting email.properties works fine.
Getting recipients.txt returns a null InputStream.

Why?

I've checked the spelling (for typos) at least 10 times. Even used copy/paste.

I can hard code the path

File base = new File("/java");
File file = new File(base, "recipients.txt");
InputStream input = new FileInputStream(file);

And that works just fine, but it's not portable enough for my needs.

How can I get the text file without hard coding it?
[ November 03, 2007: Message edited by: Marilyn de Queiroz ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried editing (or renaming) the email.properties that you think is being loaded, and ensuring that the behavior changes? Maybe it's a different one that's being loaded.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have changed the contents of email.properties and the results changed to match my changes. I also tried renaming recipients.txt to recipients.properties and interestingly (I thought), magically, the InputStream is no longer null and the app works. However, I really don't want to name a text file with a bunch of email addresses with a .properties extension since it isn't really properties.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very strange.

I don't suppose you're on Windows and have Explorer set to hide file extensions for known types? Then "text.txt" would appear as "text", and "test.txt.jpg" would appear as "test.txt". So maybe the thing that looks like recipients.txt is really something else.

Or, here's an alternate approact that might she some light if it yields unexpected results:

In principle there's no reason this will give you any different answer from what you've tried so far. But then, in principle you shouldn't be having this problem to begin with, right? So what the heck...
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was an interesting experiment. Apparently a case of my IDE trying to "help" me by copying .properties files (resources) to the build directory where the classes are, but not copying other files there. Thank you.
[ November 05, 2007: Message edited by: Marilyn de Queiroz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic