How to import .txt file in Scala -


hi im new programming, how import .txt file? code cant find file, there specific directory has put into?

my code:

object zettel01 extends app { import scala.io.source  object suchtest {   val gesch = source.fromfile("dieunendlichegeschichte.txt").getlines()   (w <- gesch) println(w) } } 

i have tried different code problem same, cant find .txt file...

thanks in advance flurry1337

every scala program run on computer java process. process have "working directory", every process on computer does. default, working directory working directory of process started it, is, current directory of shell or command-line interpreter @ time when started program.

now, means important know how start program. if using command line , start program in fashion of java mycoolprogram, current directory of shell become working directory of program. if use ide eclipse or intellij idea, typically use project folder of ide project working directory of process start.

there simple way find out quickly: can print out result of new java.io.file(".").getabsolutepath(). print full path working directory. example, can write little scala program this:

object printworkingdirectory extends app {   println(new java.io.file(".").getabsolutepath()) } 

and start it. on console, should find full path of program's working directory. if put file named "dieunendlichegeschichte.txt" in directory, program find file under file name.

of course, don't have dump files 1 directory. can make subdirectories in order organize files better. example, might put file in path "resources/text/dieunendlichegeschichte.txt".

finally, point out there different way associate resource files program, , load them. idea put code (class files) resources texts, images, csv files, xml files , 1 big file. jar file. can use classloader access resources inside jar file url.

explaining process in detail out of scope question; dropping couple of buzzwords (or other readers) can search in case want more elaborated process.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -