Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading resources using new File("src/main/resources/logfile.txt") is bad #39

Open
akauppi opened this issue Jan 24, 2016 · 0 comments
Open

Comments

@akauppi
Copy link

akauppi commented Jan 24, 2016

I'm going to use the Akka Streams sample in our Helsinki Scala Club meetup. Unfortunately, one of the samples reads a resource using a build-time relative path. This only works in development, of course, and not in production. In fact, the current way is not using the file as a resource, at all. All of this might be misleading to Scala learners.

Unfortunately, I don't know how to fix this for real. Using a Stream instead of File changes the later iteration code.

Here is a code that is somewhere in between. Creates a File out of a resource. This is done pretty often, but is not ideal, or recommended. Better than the current way, though.

    // Note: Resources should be read using '.getResourceAsStream'. While the code shows Akka Streams, it should not
    //      teach bad (nonfunctional, in production) manners. AKa240116
    //
    //val log: InputStream = getClass.getResourceAsStream("/logfile.txt")

    // read lines from a log file
    val logFile: File = new File(getClass.getResource("/logfile.txt").toURI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant