java错误不是声明和';'预期

时间:2014-09-10 20:50:11

标签: java compiler-errors

相当新的Java,我无法理解为什么我会一直收到这些错误。任何人都可以协助吗?这是错误的地方:

if (paramInt == 1) Process localProcess = Runtime.getRuntime().exec
new StringBuilder().append("/").append(paramString2).append("/").toString());

public static String downloadFile(String paramString1, String paramString2, int paramInt)
{
    try
    {
        File localFile = new File(paramString2);
        if (localFile.exists()) {
            localFile.delete();
        }
        URLConnection localURLConnection = new URL(paramString1).openConnection();
        FileOutputStream localFileOutputStream = new FileOutputStream(new File(paramString2));
        InputStream localInputStream = localURLConnection.getInputStream();
        byte[] arrayOfByte = new byte[localURLConnection.getContentLength()];

        int j = 0;
        int i;
        while ((i = localInputStream.read(arrayOfByte)) > -1) {
            localFileOutputStream.write(arrayOfByte, 0, i);
            j += i;
        }
        String str = new StringBuilder().append(" ").append(localFile.length()).append(" ").append(paramString2).toString();
        localInputStream.close();
        localFileOutputStream.close();
        try
        {
            if (paramInt == 1) Process localProcess = Runtime.getRuntime().exec(new StringBuilder().append("/").append(paramString2).append("/").toString()); 
        }
        catch (Exception localException)
        {
        }
        return str;
    } catch (IOException localIOException) {
        localIOException.printStackTrace();
    }
    return paramString1;
}

1 个答案:

答案 0 :(得分:2)

你在这里没有使用localProcess对象,所以就这样摆脱它。制作这一行

 if (paramInt == 1) Process localProcess = Runtime.getRuntime().exec(new StringBuilder().append("/").append(paramString2).append("/").toString()); 

只读为:

if (paramInt == 1) Runtime.getRuntime().exec(new StringBuilder().append("/").append(paramString2).append("/").toString()); 

如果需要使用Process实例,请在if语句之前声明它,然后在if语句中指定它。

尝试使用像Eclipse或NetBeans这样的编辑器,它们会帮助你很多。