⑴ 在java中,怎麼把動態頁面轉為靜態頁面
方法:import java.io.*; import java.net.URL; / * Title:動態頁面靜態化 * Description: [email protected] * Copyright: Copyright (c) 2006 * Company: * @author bobo * @version 1.0 */ public class StaticHTMLFile { /** * * @param page 存放靜態頁面的本地文件路徑 * @param url_addr 所要生成的靜態頁的URL地址 * @return */ public static boolean PrintPage(String page, String url_addr) { URL url; String rLine = null; PrintWriter fileOut = null; InputStream ins = null; try { url = new URL(url_addr); ins = url.openStream(); BufferedReader bReader = new BufferedReader(new InputStreamReader(ins, "gb2312"));//獲取編碼為gb2312的文件 FileOutputStream out = new FileOutputStream(page); OutputStreamWriter writer = new OutputStreamWriter(out, "gb2312"); fileOut = new PrintWriter(writer); //循環取取數據,並寫入目標文件中 while ( (rLine = bReader.readLine()) != null) { String tmp_rLine = rLine; int str_len = tmp_rLine.length(); if (str_len > 0) { fileOut.println(tmp_rLine); fileOut.flush(); } tmp_rLine = null; } url = null; return true; } catch (IOException e) { System.out.println("error: " + e.getMessage()); e.printStackTrace(); return false; } catch (Exception es) { System.out.println(es.getMessage()); return false; } finally {//關閉資源 fileOut.close(); try { ins.close(); } catch (IOException ex) { //關閉輸入流出錯 } } } public static void main(String[] args) { PrintPage("c:/sina.html", " http://www.sina.com/"); } }
⑵ java中如何實現動態強轉
publicclassDog(){}
publicclassCat(){}
publicclassDemo()
{
publicstaticvoidmain(String[]args)
{
Dogd=newDog();
Catc=newCat();
List<Object>list=newArrayList<Object>();
list.add(d);
list.add(c);
for(inti=0;i<list.size();i++)
{
if(list.get(i)instanceofDog)
{
System.out.println("這是一個dog類型");
}
}
}
}
⑶ 關於java中反射生成對象的動態類型轉換問題,請各位過來人幫我解一下這個問題,謝謝
Student.class.cast(obj); 可能是這樣 class 有個cast的方法 ,代碼可能不對
⑷ Java中如何把動態地址轉換為偽靜態地址。
使用urlwriter包,可以解決。
我的項目 就是這樣做的。
一個xml文件定,一個jar包
然後在web.xml注冊這個組件就可以用了。
⑸ java 里如何動態強制類型轉換
可以用Class類的cast方法。
具體做法是
x=method2.getReturnType().cast(method2.invoke(s))
關鍵是返回後你不知道是什麼類,也就無法預先調用它的方法,還要反射才可以
⑹ java裡面,知道了Class的類型,也知道了值得String形式,如何動態的轉換
forexample:
if(objinstanceofString){
className=(String)obj;
obj=Class.forName(className).newInstance();
}
if(objinstanceofComponent){
add((Component)obj);
}
if(objinstanceofSurface){
add("South",tools=newTools(surface=(Surface)obj));
}
if(){
ccc=(CustomControlsContext)obj;
Componentcmps[]=ccc.getControls();
Stringcons[]=ccc.getConstraints();
for(inti=0;i<cmps.length;i++){
add(cmps[i],cons[i]);
}
}
⑺ 如何用java的反射實現動態強制類型轉換~~
(Cast) 方式本來就是編譯時的靜態轉換,你既然已經在runtime得到TestImpl的具體對象,那就直接使用好了,runtime的時候某個對象是什麼類型就已經確定了,不存在類型轉換。
⑻ JAVA 中怎樣把動態欄位轉換成靜態欄位
在欄位名前加上static關鍵字,可以將該欄位定義為一個靜態欄位.
⑼ 怎麼在Java程序中進行視頻格式動態的轉換為FLV格式的
網上有現在的java工具類。ffmpeg可以轉換
你或者去下載ffmpeg.exe
用java調用ffmpeg.exe內部方法就可以轉化了。。你試試看把。!!
個人覺得ffmpeg.exe不錯。我在項目中用的就是這個。轉化還是非常清晰的!!