Skip to content

Commit e0e7fb4

Browse files
committed
Read input files from the classpath instead of a relative path
This allows reading input files independant from the current working dir.
1 parent 0c925e0 commit e0e7fb4

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.idea
33
.kotlin/
44
build
5-
src/input/**/*.txt
6-
!src/input/2024/Day99.txt
5+
src/main/resources/**/*.txt
6+
!src/main/resources/2024/Day99.txt
77
local.properties
88
/.kotlintest/

src/main/kotlin/de/ronny_h/aoc/AdventOfCode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class AdventOfCode<T>(val year: Int, val day: Int) {
1717
printAndCheck(input, ::part2, expectedPart2)
1818
}
1919

20-
private fun readInput() = Path("src/input/$year/Day${paddedDay()}.txt").readText().trim().lines()
20+
fun readInput() = AdventOfCode::class.java.getResource("/$year/Day${paddedDay()}.txt")!!.readText().trim().lines()
2121

2222
private fun paddedDay(): String = day.toString().padStart(2, '0')
2323

0 commit comments

Comments
 (0)