I have an EchoServer that I was provided to run and serve static local HTML files on my computer. It would then put out an error if the files were non-existent. I want to know how do I provide a local file path in this code?
I'm practically new to the language and do not really know how it works.
This is my main class in which I try to run the server.
def main(args: Array[String]) {
val server = new ServerSocket(9999)
while(true) {
try {
serve(server)
//Maybe the filepath goes here?
}catch {
case e: Exception => ("File not found")
}
}
}
While these two is what takes in the input
object EchoServer {
def read_and_write(in: BufferedReader, out:BufferedWriter): Unit = {
out.write(in.readLine())
out.flush()
in.close()
out.close()
}
def serve(server: ServerSocket): Unit = {
val s = server.accept()
val in = new BufferedReader(new InputStreamReader(s.getInputStream))
val out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream))
read_and_write(in, out)
s.close()
}
So if I get it to run properly it would read any existing HTML file, and if not output an error if it does not exist on my local machine.