Files.readAllLines() throws an exception every time.

I can't figure out why an exception is being thrown by this line of code, it used to work in an earlier version but now it just doesn't. Am I somehow using it wrong?
List<String> lines;
functions = functionsDir.listFiles();
for (File f : functions) {
fileCount++;
lines = Files.readAllLines(f.toPath(), StandardCharsets.UTF_8); //PROBLEM LINE
lineCount += lines.size();
}
List<String> lines;
functions = functionsDir.listFiles();
for (File f : functions) {
fileCount++;
lines = Files.readAllLines(f.toPath(), StandardCharsets.UTF_8); //PROBLEM LINE
lineCount += lines.size();
}
25 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @Devin! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Devin
DevinOP10mo ago
Here's how it looks in my code
No description
Devin
DevinOP10mo ago
No description
Devin
DevinOP10mo ago
and that's the stacktrace
Devin
DevinOP10mo ago
For additional context, I am running it from the right place as well
No description
Devin
DevinOP10mo ago
No description
Devin
DevinOP10mo ago
I just don't understand where this comes from? What does it mean "malformed input"?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
0x150
0x15010mo ago
tldr java cant really convert the bytes in the file back to text with the encoding you specified what’s in the file?
Kyo-chan
Kyo-chan10mo ago
It's weird though, a badly encoded file shouldn't throw an exception, it should produce error characters
Devin
DevinOP10mo ago
Well, what's odd about this is that I actually don't care what the text is in the file I'm not sure what file it's on, I'll try adding that code to my catch block. They're all .mcfunction files though, none of them should contain characters you wouldn't find in a minecraft command actually, at least one of them has the ☭ character in it for coin redistribution could that be it? oh I see I can't refer to F in my catch block because I think the scope is too wide?
Devin
DevinOP10mo ago
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Devin
DevinOP10mo ago
right that makes sense I'll try moving code around
Devin
DevinOP10mo ago
even the file with that weird char is UTF-8 tho
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Devin
DevinOP10mo ago
It's literally just a helper class so I don't need to remember the escape sequences
Devin
DevinOP10mo ago
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Devin
DevinOP10mo ago
yeah I think there are light/dark variants for some of them These are just the ones I thought I may need for this project
Devin
DevinOP10mo ago
Devin
DevinOP10mo ago
Holy shit
No description
Devin
DevinOP10mo ago
No idea how to fix this oh wait Looks like I can fix in in npp I just did it wrong the 1st time wow in 1999 files that was the ONLY one using ANSI encoding idk how that even got broken
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot10mo ago
Post Closed
This post has been closed by <@223590468259282954>.
Want results from more Discord servers?
Add your server