我在Liferay中 工作,我有這樣的功能:怎麼投的java.io.File到com.liferay.portal.kernel.util.File
public class NewPortlet extends MVCPortlet {
public void abc(ActionRequest arq,ActionResponse ars) throws Exception {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(arq);
FileUploader fileUp = new FileUploaderImpl();
fileUp.setFid(CounterLocalServiceUtil.increment("FileUploader.class"));
File file = (File) uploadRequest.getFile("file");
byte[] bytes = FileUtil.getBytes(file);
fileUp.setContent(Base64.objectToString(bytes));
FileUploaderLocalServiceUtil.addFileUploader(fileUp);
}
}
file所在com.liferay.portal的.kernel.util.File; 我想用上面的函數上傳圖片。我得到的UI上傳的圖片,當我點擊提交我得到以下錯誤:
ERROR [http-bio-8080-exec-37][render_portlet_jsp:154] java.lang.ClassCastException: java.io.File cannot be cast to com.liferay.portal.kernel.util.File
at com.test.image.test.NewPortlet.abc(NewPortlet.java:25)
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:153)
at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:250)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:80)
at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:220)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:579)
我應該怎麼做投java.io.File的到com.liferay.portal.kernel.util.File?
Cameron Skinner:感謝您的及時回覆。我刪除了所有的演員,它現在工作.. – 2013-03-19 07:21:55