I run in eclipse is also possible that the command window to die, I was a beginner , expert guidance !
-> javac helloworld.java
-> java helloworld
successfully display Hello World!
I lost
-> javac Javaserver.java
Javaserver.java 1 Error : Need class, interface , or enum
mport java.net. *;
public class helloworld
{
public static void main(String[] args)
{
System.out.println("Hello World!!");
}
}
import java.net.*;
import java.io.*;
public class Javaserver
{
public static void main(String args[])
{
try
{
boolean flag=true;
Socket clientSocket=null;
String inputLine;
int c;
ServerSocket sSocket=new ServerSocket(8018);
System.out.println("Server listen on:"+sSocket.getLocalPort());
while(flag)
{
clientSocket=sSocket.accept();
DataInputStream is= new DataInputStream(new BufferedInputStream(clientSocket.getInputStream()));
OutputStream os=clientSocket.getOutputStream();
while((inputLine=is.readLine())!=null)
{
if(inputLine.equals("stop"))
{
flag=false;
break;
}
else
{
System.out.println(inputLine);
while((c=System.in.read())!=-1)
{
os.write((byte)c);
if(c=='\n')
{
os.flush();
break;
}
}
}
}
is.close();
os.close();
clientSocket.close();
}
sSocket.close();
}
catch(Exception e)
{
System.out.println("Exception :"+ e.getMessage());
}
}
}
------ Solution ------------------------------------- -------
while ((inputLine = is.readLine ())! = null) {/ / readLine method obsolete,
while ((inputLine = is.readUTF ())! = null) { switch this
------ Solution ----- ---------------------------------------
1. in the command line directory for Javaserver.java
2. then run javac Javaserver.java can be compiled successfully
've tried , the source code is no problem
------ For reference only -------------------------- -------------
top about themselves , seek solutions , urgent ............
------ For reference only --------- ------------------------------
Thank you upstairs friends ......
------ For reference only ---------------------------------------
same problem solving
------ For reference only ----------------------------------- ----
------ For reference only ---------------------------------- -----
encode characters into ASCII try .
没有评论:
发表评论