?? 從jar包中獲取資源的方法.mht
字號:
FONT></I>=20
=
<LI> <I><FONT=20
=
color=3D#339900>// array with which to create&nb=
sp;the image.</FONT></I>=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>final</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/ByteArrayOutput=
Stream.java.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>ByteArrayOutputStream</U></FONT></A></B> byteAr=
rayOutputStream =3D <B><FONT=20
=
color=3D#0000ff>new</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/ByteArrayOutput=
Stream.java.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>ByteArrayOutputStream</U></FONT></A></B>();=20
=
<LI> <I><FONT=20
=
color=3D#339900>// Attempt to copy the source&nb=
sp;image data into the byte array</FONT></I>=20
=
<LI> <I><FONT=20
=
color=3D#339900>// stream, and then create an&nb=
sp;image from the result.</FONT></I>=20
=
<LI> <B><FONT=20
color=3D#0000ff>try</FONT></B>=20
=
<LI> {=20
=
<LI> <I><FONT=20
=
color=3D#339900>// Read/write image data in 1k&n=
bsp;chunks.</FONT></I>=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>final</FONT></B> <B><FONT=20
=
color=3D#0000ff>byte</FONT></B>[] bytes =3D <B><FONT=20
=
color=3D#0000ff>new</FONT></B> <B><FONT=20
color=3D#0000ff>byte</FONT></B>[1024];=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>int</FONT></B> read =3D 0;=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>while</FONT></B> ((read =3D inputStream.re=
ad(bytes)) >=3D 0)=20
=
<LI> {=20
=
<LI> byteArray=
OutputStream.write(bytes, 0, read);=20
=
<LI> }=20
<LI>
=
<LI> <I><FONT=20
=
color=3D#339900>// Create an image from the =
;resulting byte array.</FONT></I>=20
=
<LI> image =3D <=
B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/awt/Toolkit.java.h=
tml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>Toolkit</U></FONT></A></B>.getDefaultToolkit().creat=
eImage(=20
=
<LI> &nb=
sp;byteArrayOutputStream.toByteArray());=20
=
<LI> }=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>catch</FONT></B> (<B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/IOException.jav=
a.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>IOException</U></FONT></A></B> exception)=20
=
<LI> {=20
=
<LI> exception.printStackT=
race();=20
=
<LI> }=20
<LI> }=20
<LI> <B><FONT=20
=
color=3D#0000ff>return</FONT></B> image;=20
<LI> }=20
<LI>
<LI> <B><FONT=20
=
color=3D#0000ff>public</FONT></B> <B><FONT=20
=
color=3D#0000ff>static</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/lang/String.java.h=
tml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>String</U></FONT></A></B> getTextFromJar(<B><FO=
NT=20
=
color=3D#0000ff>final</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/lang/String.java.h=
tml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>String</U></FONT></A></B> filename, <B><A =
=
href=3D"http://www.javaresearch.org/source/jdk142/java/lang/Class.java.ht=
ml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>Class</U></FONT></A></B> c)=20
<LI> {=20
<LI> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/lang/String.java.h=
tml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>String</U></FONT></A></B> text =3D <F=
ONT=20
color=3D#ff33ff>""</FONT>;=20
<LI> <I><FONT=20
=
color=3D#339900>// Open a resource stream on&nbs=
p;the supplied file name.</FONT></I>=20
<LI> <B><FONT=20
=
color=3D#0000ff>final</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/InputStream.jav=
a.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>InputStream</U></FONT></A></B> inputStream =
;=3D c.getResourceAsStream(filename);=20
<LI> <I><FONT=20
=
color=3D#339900>// If the file is found...</FONT=
></I>=20
<LI> <B><FONT=20
=
color=3D#0000ff>if</FONT></B> (inputStream !=3D <B><FONT=20
color=3D#0000ff>null</FONT></B>)=20
<LI> {=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>final</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/BufferedReader.=
java.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>BufferedReader</U></FONT></A></B> in =3D&n=
bsp;<B><FONT=20
=
color=3D#0000ff>new</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/BufferedReader.=
java.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>BufferedReader</U></FONT></A></B>(<B><FONT=20
=
color=3D#0000ff>new</FONT></B> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/InputStreamRead=
er.java.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>InputStreamReader</U></FONT></A></B>(=20
=
<LI> inputStre=
am));=20
=
<LI> <B><FONT=20
color=3D#0000ff>try</FONT></B>=20
=
<LI> {=20
=
<LI> <B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/lang/String.java.h=
tml"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>String</U></FONT></A></B> s;=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>while</FONT></B> ((s =3D in.readLine())&nb=
sp;!=3D <B><FONT=20
color=3D#0000ff>null</FONT></B>)=20
=
<LI> {=20
=
<LI> text =
;+=3D s + <FONT=20
color=3D#ff33ff>"\n"</FONT>;=20
=
<LI> }=20
=
<LI> }=20
=
<LI> <B><FONT=20
=
color=3D#0000ff>catch</FONT></B> (<B><A=20
=
href=3D"http://www.javaresearch.org/source/jdk142/java/io/IOException.jav=
a.html"=20
target=3D_blank><FONT=20
=
class=3DclassLink><U>IOException</U></FONT></A></B> exception)=20
=
<LI> {=20
=
<LI> exception.printStackT=
race();=20
=
<LI> }=20
<LI> }=20
<LI> <B><FONT=20
=
color=3D#0000ff>return</FONT></B> text;=20
<LI> }=20
<LI>} =
</LI></OL></DIV></SPAN><BR></DIV></TD>
<TD=20
=
width=3D8></TD></TR></TBODY></TABLE><BR><BR></DIV></TD></TR></TBODY></TAB=
LE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><IMG height=3D8 alt=3D""=20
src=3D"http://www.35dx.com/images/leiye_1_14.gif"=20
=
width=3D556></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
<TD width=3D186 =
background=3Dhttp://www.35dx.com/images/leiye_1_11.gif>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"27%" border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop></TD></TR>
<TR>
<TD vAlign=3Dtop>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
border=3D0>
<TBODY>
<TR>
<TD =
background=3Dhttp://www.35dx.com/images/leiye_1_04.gif=20
height=3D28>
<SCRIPT language=3Djavascript src=3D""></SCRIPT>
<SCRIPT language=3Djavascript src=3D""></SCRIPT>
</TD></TR>
<TR>
<TD><IMG height=3D8 alt=3D1=20
=
src=3D"http://www.35dx.com/images/leiye_1_13.gif"></TD></TR></TBODY></TAB=
LE></TD></TR>
<TR>
<TD =
vAlign=3Dtop> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<STYLE type=3Dtext/css>.style1 {
COLOR: #ffffff
}
</STYLE>
<TABLE borderColor=3D#666666 cellSpacing=3D0 cellPadding=3D8 width=3D778 =
align=3Dcenter=20
bgColor=3D#f5f5f5 border=3D1>
<TBODY>
<TR>
<TD borderColor=3D#f5f5f5>
<TABLE class=3Dtxt12 cellSpacing=3D0 cellPadding=3D0 width=3D"98%" =
align=3Dcenter=20
border=3D0>
<TBODY>
<TR>
<TD height=3D26><FONT=20
=
color=3D#cc0000>=B5=E7=D7=D3=C9=CC=CE=F1=B4=F3=D1=A7=B0=E6=C8=A8=D3=EB=C3=
=E2=D4=F0=C9=F9=C3=F7=A3=BA</FONT></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=3D0 cellPadding=3D3 width=3D"98%" =
align=3Dcenter border=3D0>
<TBODY>
<TR>
<TD class=3Dtxt12 vAlign=3Dtop align=3Dmiddle width=3D"3%"=20
height=3D37>=A2=D9<BR>=A1=A1</TD>
<TD class=3Dtxt12 width=3D"97%"=20
=
height=3D37>=B7=B2=B1=BE=CD=F8=D7=A2=C3=F7=A1=B0=C0=B4=D4=B4=A3=BA35DX=A1=
=B1=B5=C4=CB=F9=D3=D0=D7=F7=C6=B7=A3=AC=B0=E6=C8=A8=BE=F9=CA=F4=D3=DA=B5=E7=
=D7=D3=C9=CC=CE=F1=B4=F3=D1=A7=A3=AC=CE=B4=BE=AD=B1=BE=CD=F8=CA=DA=C8=A8=B2=
=BB=B5=C3=D7=AA=D4=D8=A1=A2=D5=AA=B1=E0=BB=F2=C0=FB=D3=C3=C6=E4=CB=FC=B7=BD=
=CA=BD=CA=B9=D3=C3=C9=CF=CA=F6=D7=F7=C6=B7=A1=A3=D2=D1=BE=AD=B1=BE=CD=F8=CA=
=DA=C8=A8=CA=B9=D3=C3=D7=F7=C6=B7=B5=C4=A3=AC=D3=A6=D4=DA=CA=DA=C8=A8=B7=B6=
=CE=A7=C4=DA=CA=B9=D3=C3=A3=AC=B2=A2=D7=A2=C3=F7=A1=B0=C0=B4=D4=B4=A3=BA=B5=
=E7=D7=D3=C9=CC=CE=F1=B4=F3=D1=A7=A1=B1=A1=A3=CE=A5=B7=B4=C9=CF=CA=F6=C9=F9=
=C3=F7=D5=DF=A3=AC=B1=BE=CD=F8=BD=AB=D7=B7=BE=BF=C6=E4=CF=E0=B9=D8=B7=A8=C2=
=C9=D4=F0=C8=CE=A1=A3</TD></TR></TBODY></TABLE>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -