Skip to content

Text file should be read from the file name that's pass in, not a resource #1

@DavidWhitlock

Description

@DavidWhitlock

Hi, @DFedron.

I was able to reproduce the issue that the grading scripts encountered on a local build of your repository:

$ java -jar target/apptbook-2021.0.0.jar -textFile huidong/huidong.txt -print Project2 "This is Test 7" 01/07/2021 07:00 01/17/2021 17:00
Exception in thread "main" java.io.IOException: No such file or directory
	at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.base/java.io.File.createNewFile(File.java:1024)
	at edu.pdx.cs410J.huidong.Project2.constructPath(Project2.java:189)
	at edu.pdx.cs410J.huidong.Project2.main(Project2.java:143)

I looked at the code and I think the problem is here:

File f1 = new File(this.getClass().getResource("").getPath());

When I ran the above command line with a debugger attached, I saw that the RealPath variable has more information than you probably intended:

image

I think all you need to do is create a new File(fileName) and it should work as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions