Can you please write this java code in Scala.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class SimpleSocketClientExample
{
public static void main( String[] args )
{
if( args.length < 2 )
{
System.out.println( "Usage: SimpleSocketClientExample <server> <path>" );
System.exit( 0 );
}
String server = args[ 0 ];
String path = args[ 1 ];
System.out.println( "Loading contents of URL: " + server );
try
{
// Connect to the server
Socket socket = new Socket( server, 80 );
// Create input and output streams to read from and write to the server
PrintStream out = new PrintStream( socket.getOutputStream() );
BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream() ) );
// Follow the HTTP protocol of GET <path> HTTP/1.0 followed by an empty line
out.println( "GET " + path + " HTTP/1.0" );
out.println();
// Read data from the server until we finish reading the document
String line = in.readLine();
while( line != null )
{
System.out.println( line );
line = in.readLine();
}
// Close our streams
in.close();
out.close();
socket.close();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintStream
import java.net.Socket
//remove if not needed
import scala.collection.JavaConversions._
object SimpleSocketClientExample {
def main(args: Array[String]): Unit = {
if (args.length < 2) {
println("Usage:
SimpleSocketClientExample <server> <path>")
System.exit(0)
}
val server: String = args(0)
val path: String = args(1)
println("Loading contents of URL: " +
server)
try {
// Connect to the server
val socket: Socket = new
Socket(server, 80)
// Create input and output streams to read from and write to the
server
val out: PrintStream = new
PrintStream(socket.getOutputStream)
val in: BufferedReader = new
BufferedReader(
new
InputStreamReader(socket.getInputStream))
// Follow the HTTP protocol of GET <path> HTTP/1.0 followed
by an empty line
out.println("GET " + path + "
HTTP/1.0")
out.println()
// Read data from the server until we finish reading the
document
var line: String =
in.readLine()
while (line != null) {
println(line)
line =
in.readLine()
}
// Close our streams
in.close()
out.close()
socket.close()
} catch {
case e: Exception =>
e.printStackTrace()
}
}
}
Can you please write this java code in Scala. import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import...