博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
IT圈中人
o~_~o
ujnjt.cublog.cn
管理博客
发表文章
留言
收藏夹
博客圈
音乐
相册
文章
· 数据库
· java
· 操作系统
首页
关于作者
姓名:jiang tao 职业:it 年龄:26 位置:.cn 个性介绍:吾将上下而求索
||
<<
>>
||
我的分类
文章列表 - java
常用排序算法java实现
<DIV>经常我们会用到一些排序算法,下面是用java的实现</DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#999999 cellSpacing=0 cellPadding=0 width="95%" bgColor=#f1f1f1 border=1> <TBODY> <TR> <TD> <P style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN style="COLOR: #000000"><SPAN style="COLOR: #0000ff">package</SPAN> jt<SPAN style="COLOR: #0000cc">.</SPAN>test<SPAN style="COLOR: #0000cc">;</SPAN><BR><BR><SPAN style="COLOR: #0000f……
查看全文
发表于:2007-06-06 ┆
阅读(188)
┆
评论(0)
java中文件操作大全
<DIV>本文为本人在工作学习中的总结,每个方法都经过测试,记在博客上一方面是为了自己日后工作方便,另一方面是为了给大家提供方便,节约时间。 <P><STRONG> 一.获得控制台用户输入的信息</STRONG></P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_0_55_Open_Image onclick="this.style.display='none'; document.getElementById('_0_55_Open_Text').style.display='none'; document.getElementById('_0_55_Closed_Image').style.display='inline'; document.getElementById('_0_55_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_0_55_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_0_55_Closed_Text').style.display='none'; document.getElementById('_0_55_Open_Image').style.display='inline'; document.getElementById('_0_55_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=_0_55_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">/** */</SPAN><SPAN id=_0_55_Open_Text><SPAN style="COLOR: rgb(0,128,0)">/**</SPAN><SPAN style="COLOR: rgb(0,128,0)">获得控制台用户输入的信息<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@return</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@throws</SPAN><SPAN style="COLOR: rgb(0,128,0)"> IOException<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,128,0)">*/</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG id=_108_357_Open_Image style="DISPLAY: inline" onclick="this.style.display='none'; document.getElementById('_108_357_Open_Text').style.display='none'; document.getElementById('_108_357_Closed_Image').style.display='inline'; document.getElementById('_108_357_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_108_357_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_108_357_Closed_Text').style.display='none'; document.getElementById('_108_357_Open_Image').style.display='inline'; document.getElementById('_108_357_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">public</SPAN><SPAN style="COLOR: rgb(0,0,0)"> String getInputMessage() </SPAN><SPAN style="COLOR: rgb(0,0,255)">throws</SPAN><SPAN style="COLOR: rgb(0,0,0)"> IOException</SPAN><SPAN id=_108_357_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_108_357_Open_Text style="DISPLAY: inline"><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> System.out.println(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">请输入您的命令∶</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">byte</SPAN><SPAN style="COLOR: rgb(0,0,0)"> buffer[]</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">byte</SPAN><SPAN style="COLOR: rgb(0,0,0)">[</SPAN><SPAN style="COLOR: rgb(0,0,0)">1024</SPAN><SPAN style="COLOR: rgb(0,0,0)">];<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> count</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">System.in.read(buffer);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">char</SPAN><SPAN style="COLOR: rgb(0,0,0)">[] ch</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">char</SPAN><SPAN style="COLOR: rgb(0,0,0)">[count</SPAN><SPAN style="COLOR: rgb(0,0,0)">-</SPAN><SPAN style="COLOR: rgb(0,0,0)">2</SPAN><SPAN style="COLOR: rgb(0,0,0)">];</SPAN><SPAN style="COLOR: rgb(0,128,0)">//</SPAN><SPAN style="COLOR: rgb(0,128,0)">最后两位为结束符,删去不要</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">for</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> i</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">0</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN style="COLOR: rgb(0,0,0)">count</SPAN><SPAN style="COLOR: rgb(0,0,0)">-</SPAN><SPAN style="COLOR: rgb(0,0,0)">2</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">)<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> ch[i]</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">char</SPAN><SPAN style="COLOR: rgb(0,0,0)">)buffer[i];<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> String str</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> String(ch);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">return</SPAN><SPAN style="COLOR: rgb(0,0,0)"> str;<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> }</SPAN></SPAN></DIV></DIV> <P>可以返回用户输入的信息,不足之处在于不支持中文输入,有待进一步改进。</P> <P><STRONG>二.复制文件</STRONG></P> <P>1.以文件流的方式复制文件</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_0_88_Open_Image onclick="this.style.display='none'; document.getElementById('_0_88_Open_Text').style.display='none'; document.getElementById('_0_88_Closed_Image').style.display='inline'; document.getElementById('_0_88_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_0_88_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_0_88_Closed_Text').style.display='none'; document.getElementById('_0_88_Open_Image').style.display='inline'; document.getElementById('_0_88_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=_0_88_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">/** */</SPAN><SPAN id=_0_88_Open_Text><SPAN style="COLOR: rgb(0,128,0)">/**</SPAN><SPAN style="COLOR: rgb(0,128,0)">以文件流的方式复制文件<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> src 文件源目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> dest 文件目的目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@throws</SPAN><SPAN style="COLOR: rgb(0,128,0)"> IOException <BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,128,0)">*/</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG id=_154_489_Open_Image onclick="this.style.display='none'; document.getElementById('_154_489_Open_Text').style.display='none'; document.getElementById('_154_489_Closed_Image').style.display='inline'; document.getElementById('_154_489_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_154_489_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_154_489_Closed_Text').style.display='none'; document.getElementById('_154_489_Open_Image').style.display='inline'; document.getElementById('_154_489_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">public</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">void</SPAN><SPAN style="COLOR: rgb(0,0,0)"> copyFile(String src,String dest) </SPAN><SPAN style="COLOR: rgb(0,0,255)">throws</SPAN><SPAN style="COLOR: rgb(0,0,0)"> IOException</SPAN><SPAN id=_154_489_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_154_489_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> FileInputStream in</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> FileInputStream(src);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> File file</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> File(dest);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">if</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,0)">!</SPAN><SPAN style="COLOR: rgb(0,0,0)">file.exists())<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> file.createNewFile();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> FileOutputStream out</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> FileOutputStream(file);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> c;<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">byte</SPAN><SPAN style="COLOR: rgb(0,0,0)"> buffer[]</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">byte</SPAN><SPAN style="COLOR: rgb(0,0,0)">[</SPAN><SPAN style="COLOR: rgb(0,0,0)">1024</SPAN><SPAN style="COLOR: rgb(0,0,0)">];<BR><IMG id=_401_457_Open_Image onclick="this.style.display='none'; document.getElementById('_401_457_Open_Text').style.display='none'; document.getElementById('_401_457_Closed_Image').style.display='inline'; document.getElementById('_401_457_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_401_457_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_401_457_Closed_Text').style.display='none'; document.getElementById('_401_457_Open_Image').style.display='inline'; document.getElementById('_401_457_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">while</SPAN><SPAN style="COLOR: rgb(0,0,0)">((c</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">in.read(buffer))</SPAN><SPAN style="COLOR: rgb(0,0,0)">!=-</SPAN><SPAN style="COLOR: rgb(0,0,0)">1</SPAN><SPAN style="COLOR: rgb(0,0,0)">)</SPAN><SPAN id=_401_457_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_401_457_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">for</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> i</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">0</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN style="COLOR: rgb(0,0,0)">c;i</SPAN><SPAN style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">)<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> out.write(buffer[i]); <BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> in.close();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> out.close();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> }</SPAN></SPAN></DIV></DIV> <P>该方法经过测试,支持中文处理,并且可以复制多种类型,比如txt,xml,jpg,doc等多种格式</P> <P><STRONG>三.写文件</STRONG></P> <P>1.利用PrintStream写文件</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_0_18_Open_Image onclick="this.style.display='none'; document.getElementById('_0_18_Open_Text').style.display='none'; document.getElementById('_0_18_Closed_Image').style.display='inline'; document.getElementById('_0_18_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_0_18_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_0_18_Closed_Text').style.display='none'; document.getElementById('_0_18_Open_Image').style.display='inline'; document.getElementById('_0_18_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=_0_18_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">/** */</SPAN><SPAN id=_0_18_Open_Text><SPAN style="COLOR: rgb(0,128,0)">/**</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * 文件输出示例<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,128,0)">*/</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG id=_50_289_Open_Image onclick="this.style.display='none'; document.getElementById('_50_289_Open_Text').style.display='none'; document.getElementById('_50_289_Closed_Image').style.display='inline'; document.getElementById('_50_289_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_50_289_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_50_289_Closed_Text').style.display='none'; document.getElementById('_50_289_Open_Image').style.display='inline'; document.getElementById('_50_289_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">public</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">void</SPAN><SPAN style="COLOR: rgb(0,0,0)"> PrintStreamDemo()</SPAN><SPAN id=_50_289_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_50_289_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG id=_58_224_Open_Image onclick="this.style.display='none'; document.getElementById('_58_224_Open_Text').style.display='none'; document.getElementById('_58_224_Closed_Image').style.display='inline'; document.getElementById('_58_224_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_58_224_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_58_224_Closed_Text').style.display='none'; document.getElementById('_58_224_Open_Image').style.display='inline'; document.getElementById('_58_224_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">try</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN id=_58_224_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_58_224_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> FileOutputStream out</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> FileOutputStream(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">D:/test.txt</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> PrintStream p</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> PrintStream(out);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">for</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> i</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">0</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN style="COLOR: rgb(0,0,0)">10</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">)<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> p.println(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">This is </SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">i</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)"> line</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG id=_258_286_Open_Image onclick="this.style.display='none'; document.getElementById('_258_286_Open_Text').style.display='none'; document.getElementById('_258_286_Closed_Image').style.display='inline'; document.getElementById('_258_286_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_258_286_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_258_286_Closed_Text').style.display='none'; document.getElementById('_258_286_Open_Image').style.display='inline'; document.getElementById('_258_286_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">catch</SPAN><SPAN style="COLOR: rgb(0,0,0)"> (FileNotFoundException e) </SPAN><SPAN id=_258_286_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_258_286_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> e.printStackTrace();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> }</SPAN></SPAN></DIV></DIV> <P>2.利用StringBuffer写文件</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_52_476_Open_Image onclick="this.style.display='none'; document.getElementById('_52_476_Open_Text').style.display='none'; document.getElementById('_52_476_Closed_Image').style.display='inline'; document.getElementById('_52_476_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_52_476_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_52_476_Closed_Text').style.display='none'; document.getElementById('_52_476_Open_Image').style.display='inline'; document.getElementById('_52_476_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: rgb(0,0,255)">public</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">void</SPAN><SPAN style="COLOR: rgb(0,0,0)"> StringBufferDemo() </SPAN><SPAN style="COLOR: rgb(0,0,255)">throws</SPAN><SPAN style="COLOR: rgb(0,0,0)"> IOException...</SPAN><SPAN id=_52_476_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_52_476_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> File file</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> File(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">/root/sms.log</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">if</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,0)">!</SPAN><SPAN style="COLOR: rgb(0,0,0)">file.exists())<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> file.createNewFile();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> FileOutputStream out</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> FileOutputStream(file,</SPAN><SPAN style="COLOR: rgb(0,0,255)">true</SPAN><SPAN style="COLOR: rgb(0,0,0)">); <BR><IMG id=_265_441_Open_Image onclick="this.style.display='none'; document.getElementById('_265_441_Open_Text').style.display='none'; document.getElementById('_265_441_Closed_Image').style.display='inline'; document.getElementById('_265_441_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_265_441_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_265_441_Closed_Text').style.display='none'; document.getElementById('_265_441_Open_Image').style.display='inline'; document.getElementById('_265_441_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">for</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">int</SPAN><SPAN style="COLOR: rgb(0,0,0)"> i</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">0</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN style="COLOR: rgb(0,0,0)">10000</SPAN><SPAN style="COLOR: rgb(0,0,0)">;i</SPAN><SPAN style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">)...</SPAN><SPAN id=_265_441_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_265_441_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> StringBuffer sb</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> StringBuffer();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> sb.append(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">这是第</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">i</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">行:前面介绍的各种方法都不关用,为什么总是奇怪的问题 </SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> out.write(sb.toString().getBytes(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">utf-8</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">));<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"> <BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> out.close();<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> }</SPAN></SPAN></DIV></DIV> <P>该方法可以设定使用何种编码,有效解决中文问题。</P> <P><STRONG>四.文件重命名</STRONG></P> <P></P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_1_97_Open_Image onclick="this.style.display='none'; document.getElementById('_1_97_Open_Text').style.display='none'; document.getElementById('_1_97_Closed_Image').style.display='inline'; document.getElementById('_1_97_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_1_97_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1_97_Closed_Text').style.display='none'; document.getElementById('_1_97_Open_Image').style.display='inline'; document.getElementById('_1_97_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN id=_1_97_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">/** */</SPAN><SPAN id=_1_97_Open_Text><SPAN style="COLOR: rgb(0,128,0)">/**</SPAN><SPAN style="COLOR: rgb(0,128,0)">文件重命名<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> path 文件目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> oldname 原来的文件名<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> newname 新文件名<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,128,0)">*/</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG id=_168_555_Open_Image onclick="this.style.display='none'; document.getElementById('_168_555_Open_Text').style.display='none'; document.getElementById('_168_555_Closed_Image').style.display='inline'; document.getElementById('_168_555_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_168_555_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_168_555_Closed_Text').style.display='none'; document.getElementById('_168_555_Open_Image').style.display='inline'; document.getElementById('_168_555_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">public</SPAN><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN style="COLOR: rgb(0,0,255)">void</SPAN><SPAN style="COLOR: rgb(0,0,0)"> renameFile(String path,String oldname,String newname)</SPAN><SPAN id=_168_555_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_168_555_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG id=_206_540_Open_Image onclick="this.style.display='none'; document.getElementById('_206_540_Open_Text').style.display='none'; document.getElementById('_206_540_Closed_Image').style.display='inline'; document.getElementById('_206_540_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_206_540_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_206_540_Closed_Text').style.display='none'; document.getElementById('_206_540_Open_Image').style.display='inline'; document.getElementById('_206_540_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">if</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,0)">!</SPAN><SPAN style="COLOR: rgb(0,0,0)">oldname.equals(newname))</SPAN><SPAN id=_206_540_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_206_540_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{</SPAN><SPAN style="COLOR: rgb(0,128,0)">//</SPAN><SPAN style="COLOR: rgb(0,128,0)">新的文件名和以前文件名不同时,才有必要进行重命名</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)"> File oldfile</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> File(path</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">/</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">oldname);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> File newfile</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)"> File(path</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">/</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">newname);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">if</SPAN><SPAN style="COLOR: rgb(0,0,0)">(newfile.exists())</SPAN><SPAN style="COLOR: rgb(0,128,0)">//</SPAN><SPAN style="COLOR: rgb(0,128,0)">若在该目录下已经有一个文件和新文件名相同,则不允许重命名</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)"> System.out.println(newname</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">已经存在!</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">);<BR><IMG id=_472_529_Open_Image onclick="this.style.display='none'; document.getElementById('_472_529_Open_Text').style.display='none'; document.getElementById('_472_529_Closed_Image').style.display='inline'; document.getElementById('_472_529_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=_472_529_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_472_529_Closed_Text').style.display='none'; document.getElementById('_472_529_Open_Image').style.display='inline'; document.getElementById('_472_529_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,0,255)">else</SPAN><SPAN id=_472_529_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN id=_472_529_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> oldfile.renameTo(newfile);<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"> <BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"> <BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> }</SPAN></SPAN></DIV></DIV><SPAN style="FONT-WEIGHT: bold">五.转移文件目录</SPAN> <P> </P> <P>转移文件目录不等同于复制文件,复制文件是复制后两个目录都存在该文件,而转移文件目录则是转移后,只有新目录中存在该文件。 </P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> <DIV><IMG id=_4_178_Open_Image onclick="this.style.display='none'; document.getElementById('_4_178_Open_Text').style.display='none'; document.getElementById('_4_178_Closed_Image').style.display='inline'; document.getElementById('_4_178_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_4_178_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_4_178_Closed_Text').style.display='none'; document.getElementById('_4_178_Open_Image').style.display='inline'; document.getElementById('_4_178_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: rgb(0,0,0)"> </SPAN><SPAN id=_4_178_Closed_Text style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">/** */</SPAN><SPAN id=_4_178_Open_Text><SPAN style="COLOR: rgb(0,128,0)">/**</SPAN><SPAN style="COLOR: rgb(0,128,0)">转移文件目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> filename 文件名<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> oldpath 旧目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> newpath 新目录<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align=top> * </SPAN><SPAN style="COLOR: rgb(128,128,128)">@param</SPAN><SPAN style="COLOR: rgb(0,128,0)"> cover 若新目录下存在和转移文件具有相同文件名的文件时,是否覆盖新目录下文件,cover=true将会覆盖原文件,否则不操作<BR><IMG alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align=top> </SPAN><SPAN style="COLOR: rgb(0,128,0)">*/</SPAN></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG id=_272_685_Open_Image onclick="this.style.display='none'; document.getElementById('_272_685_Open_Text').style.display='none'; document.getElementById('_272_685_Closed_Image').style.display='inline'; document.getElementById('_272_685_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=_272_685_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_272_685_Closed_Text').style.display='none'; document.getElementById('_272_685_Open_Image').style.display='inline'; document.getElementById('_272_685_Open_Text').style.display='inline';" alt="" src="
查看全文
发表于:2007-06-05 ┆
阅读(176)
┆
评论(0)
编写线程安全的JSP程序
<DIV> <DIV class=con_sample> <P>JSP默认是以多线程方式执行的,这是JSP与ASP,PHP,PERL等脚本语言不一样的地方,也是它的优势之一,但如果不注意多线程中的同步问题,会使所写的JSP程序有难以发现的错误。下面以一个例子说明JSP中的多线程问题及解决方法。</P></DIV> <DIV class=con_all> <P> <P> 作者:徐春金,BEA 资深技术顾问,加入BEA中国多年,在门户技术、RFID解决方案上有着丰富的经验。</P> <P>JSP默认是以多线程方式执行的,这是JSP与ASP,PHP,PERL等脚本语言不一样的地方,也是它的优势之一,但如果不注意多线程……
查看全文
发表于:2007-06-05 ┆
阅读(100)
┆
评论(0)
JDBC4中的新特性
<DIV> <DIV>看了Frank Sommers在artima上的一篇短文,没想到JDBC变化那么快,都快到JDBC4了。想想自己使用JDBC的时候,依稀记得好像是JDBC1.1,还没到2的样子。</DIV> <DIV> </DIV> <DIV>以下是他的短文里的一些内容。</DIV> <DIV> </DIV> <DIV>在JCP草案里(JSR221),JDBC4在易用性和开发效率上作为重点被考虑,而且会考虑SQL2003标准中的数据类型,包括SQL的native XML类型,里边还专门提供了把字段的值设为RowID的接口。如:</DIV> <DIV> <TABLE style="HEIGHT: 76px" cellSpacing=0 cellPadding=0 bgColor=……
查看全文
发表于:2007-06-05 ┆
阅读(132)
┆
评论(0)
JSP 数据库联接大全
<DIV> <P>现在有好多初学jsp的网友经常会问数据库怎么连接啊,怎么老出错啊?所以我集中的在这写篇文章供大家参考,其实这种把数据库逻辑全部放在jsp里未必是好的做法,但是有利于初学者学习,所以我就这样做了,当大家学到一定程度的时候,可以考虑用MVC的模式开发。在练习这些代码的时候,你一定将jdbc的驱动程序放到服务器的类路径里,然后要在数据库里建一个表test,有两个字段比如为test1,test2,可以用下面SQL建 <BR>create table test(test1 varchar(20),test2 varchar(20) <BR>然后向这个表写入一条测试纪录 <BR>那么现在开始我们……
查看全文
发表于:2007-06-05 ┆
阅读(150)
┆
评论(0)
浅谈final
<DIV> <P><FONT color=#000000>对与java中的final变量,java编译器是进行了优化的。每个使用了final类型变量的地方都不会通过连接而进行访问。比如说Test类中使用了Data类中一个final的int数字fNumber=77,这时候,java编译器会将77这个常数编译到Test类的指令码或者常量池中。这样,每次Test类用到fNumber的时候,不会通过引用连接到Data类中进行读取,而是直接使用自己保存在类文件中的副本。<BR>用程序说话:<BR>Test.java:</FONT></P> <P><SPAN class=Code><FONT color=#000000>public class Test{<BR> public static void mai……
查看全文
发表于:2007-06-05 ┆
阅读(137)
┆
评论(0)