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

How to load text file via relative path? #399

Open
dnltsk opened this issue Apr 3, 2023 · 2 comments
Open

How to load text file via relative path? #399

dnltsk opened this issue Apr 3, 2023 · 2 comments

Comments

@dnltsk
Copy link

dnltsk commented Apr 3, 2023

I want to open files that are located beside the main script file.

@file:Import("Models.kts")
val data = Gson().fromJson(FileReader("data.json"), Models.Data::class.java)

fails with

java.io.FileNotFoundException: data.json (No such file or directory)

Using the absolute path works straight away. Cannot find anything guidance in the documentation.

@dnltsk
Copy link
Author

dnltsk commented Apr 3, 2023

The sample code above is working finr when I execute the script from console like

> ./Main.kts

But not when executed from within IntelliJ, when the project was created via

> kscript --idea Main.kts

Then, it expects to find the text file inside the .../Library/Caches/kscript/idea_59... path.

@aartiPl
Copy link
Collaborator

aartiPl commented Jun 13, 2023

Yes, because --idea creates IntelliJ project, which is intended for debugging, not as a runtime environment. The project is located in the cache, so you must copy the data file if you want to use it.

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

2 participants