我是一个试图学习Java的PHP/Mysql程序员,我一直坚持如何用它来压缩文件:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
这是示例代码:
import java.net.*;
import java.io.*;
public class GreetingClient
{
public static void main(String [] args)
{
String serverName = args[0];
int port = Integer.parseInt(args[1]);
try
{
System.out.println("Connecting to " + serverName
+ " on port " + port);
Socket client = new Socket(serverName, port);
System.out.println("Just connected to "
+ client.getRemoteSocketAddress());
OutputStream outToServer = client.getOutputStream();
DataOutputStream out =
new DataOutputStream(outToServer);
out.writeUTF("Hello from "
+ client.getLocalSocketAddress());
InputStream inFromServer = client.getInputStream();
DataInputStream in =
new DataInputStream(inFromServer);
System.out.println("Server says " + in.readUTF());
client.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行时尝试在Windows命令提示符下使用javac命令将此文件从.java文件编译为要在网页中调用的.class文件,我收到错误消息:
bad class file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the classpath.
public static void main(String[] args) {
Run Code Online (Sandbox Code Playgroud)
如果编译一个像这样的.java文件:
import java.applet.Applet;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
public class applet_test extends Applet {
private InetAddress addr = null;
public void init() {
try {
addr = InetAddress.getLocalHost();
}
catch (UnknownHostException e) {
System.exit(0);
}
}
public InetAddress getLHost() {
return addr;
}
}
Run Code Online (Sandbox Code Playgroud)
我没有错误,.java文件编译成.class文件,我能够在网页中使用.class文件就好了.
不知道我做错了什么.
多谢你们!
好的,现在,当我运行此命令时:
C:\ > javac GreetingClient.java
Run Code Online (Sandbox Code Playgroud)
我明白了:
GreetingClient.java:9: cannot find symbol
symbol : method parseInt(GreetingClient)
location: class java.lang.Integer
int port = Integer.parseInt(args[1]);
^
GreetingClient.java:14: cannot find symbol
symbol : constructor Socket(GreetingClient,int)
location: class java.net.Socket
Socket client = new Socket(serverName, port);
^
2 errors
Run Code Online (Sandbox Code Playgroud)
同样,我在使用此行的文件上运行javac命令时似乎只会出错:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
我知道我错过了什么,任何帮助都会受到赞赏.
| 归档时间: |
|
| 查看次数: |
4055 次 |
| 最近记录: |