2011-01-25 49 views
2
package com.cordys.report; 

import java.io.FileInputStream; 

import org.apache.commons.codec.binary.Base64; 


public class Encode { 
public static String encodeFileStream(String filePath) //file path ex : C:\Program Files\Cordys\Web\reports\I0001180.pdf 
{  
try { 
    FileInputStream fin = new FileInputStream("E:/CSS Document/Test.pdf"); 
    StringBuffer sb=new StringBuffer(); 
    int lineLength = 72; 
    byte[] buf = new byte[lineLength/4*3]; 
    while (true) { 
    int len = fin.read(buf); 
    if (len <= 0) { 
     break; 
    } 
    sb.append(Base64.encode(buf)); 

    return sb.toString(); 
} 
} 
catch(Exception e) { 
    return e.getMessage(); 
} 
} 



} 
+0

看起来像这样的精确副本:http://stackoverflow.com/questions/4790826/non-static-method-encodebyte-cannot-be-referenced-from-a-static-context连类使用的是相同的。 – 2011-01-27 06:43:21

+0

好吧,到目前为止,您已设法创建六个未注册的帐户。我已经将它们合并在一起(http://stackoverflow.com/users/587133/monika)。请注册一个账户(你已经提出了六个问题,它的时间),然后FLAG这一个。当您举报时,请选择其他,然后让我将您的帐户合并到您的帐户中。 – Will 2011-01-28 13:10:47

回答

4

方法Base64.encode()不是static。你必须创建Base64类的实例,然后调用该方法,即像做new Base64().encode(bytes)

3

由于该方法不是静态的,因此只能从其封闭类的实例中调用,因此需要创建新的对象并调用encode

Base64 b = new Base64(); 
sb.append(b.encode(buf)); 
相关问题