<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "如何用程式寫出一個文字檔案，編碼為Big-5"]]></title>
		<link>http://www.andowson.com/posts/list/5.page</link>
		<description><![CDATA[Latest messages posted in the topic "如何用程式寫出一個文字檔案，編碼為Big-5"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>如何用程式寫出一個文字檔案，編碼為Big-5</title>
				<description><![CDATA[ 我有一個問題就是將讀取到且是在螢幕所顯示出來的另存一個.txt檔案要如何做？<br /> 我參考範例文件：http://pastie.org/3262724<br /> 仍然兜不太出來，懇請指點&lt;(_ _)&gt;<br /> <br /> 我的程式碼：<br /> [code]<br /> import java.io.*;<br /> import java.io.File;<br /> import java.io.IOException;<br /> import java.util.Scanner;<br /> import java.util.List;<br /> <br /> import org.jdom.Document;<br /> import org.jdom.Element;<br /> import org.jdom.JDOMException;<br /> import org.jdom.input.SAXBuilder;<br /> <br /> public class WriteFile {<br />     public static void main(String[] args) throws IOException {<br />     SAXBuilder builder = new SAXBuilder();<br />     File xmlFile = new File("C:\\JAVA_WORK\\test1.xml");<br />     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));<br />     System.out.print("請輸入分類號："); <br />     String s = br.readLine();<br />     System.out.print("------------------------------------------\n");<br />     boolean found = false;<br />     FileWriter fw;<br />     String  Signal="";<br />     String lineSep = System.getProperty("line.separator");<br /> <br />     if (s != null) {<br />              try {<br />                        Document document = (Document) builder.build(xmlFile);<br />                        Element rootNode = document.getRootElement();<br />                        List list = rootNode.getChildren("ROW");<br /> <br />                        for (int i = 0; i &lt; list.size(); i++) {<br />                           Element node = (Element) list.get(i);<br />                            if (node.getChildText("分類號").equals(s)) {<br />                                  System.out.println("年度號：" + node.getChildText("年度號"));<br />                                  System.out.println("分類號：" + node.getChildText("分類號"));<br />                                  System.out.println("案次號：" + node.getChildText("案次號"));<br />                                  Scanner input = new Scanner(System.in);		      <br />                                  input.hasNextLine();<br />                                  found = true;<br />                             }<br />                         }<br />                         fw= new FileWriter("c:\\JAVA_WORK\\T02.txt");<br />                         fw.write(Signal);<br />                         fw.close();<br />                         Signal += "年度號：" + node.getChildText("年度號")+lineSep+ "分類號：" + node.getChildText("分類號")+lineSep+ "案次號：" + node.getChildText("案次號")+lineSep;<br />                         } catch(Exception e) {<br />                            System.out.println("發生" + e + "例外無法寫檔！");  	 <br />                         } catch (IOException io) {<br />                            System.out.println(io.getMessage());<br />                         } catch (JDOMException jdomex) {<br />                            System.out.println(jdomex.getMessage());<br />                         } <br />                     }<br />                        if (!found) {<br />                             System.out.println("\n查無此分類號！請重新輸入...");<br />                        } else {System.out.println("\n搜尋結束...");}<br />                }  <br /> }<br /> [/code]<br /> 而我只要寫入僅三項年度號、分類號和案次號；存檔目的地：C:\JAVA_WORK\Write01.txt <br /> 執行結果示意圖如下：<br /> [code]<br /> C:\JAVA_WORK\JAVA\HW&gt; javac SearchXML.java<br /> <br /> C:\JAVA_WORK\JAVA\HW&gt; java SearchXMLFile<br /> 請輸入分類號：0299<br /> <br /> 年度號：70<br /> 分類號：0299<br /> 案次號：001<br /> <br /> 年度號：79<br /> 分類號：0299<br /> 案次號：011<br /> <br /> 年度號：78<br /> 分類號：0299<br /> 案次號：013<br /> <br /> 搜尋完畢...<br /> <br /> C:\JAVA_WORK\JAVA\HW&gt; <br /> [/code]<br /> 然後存檔為.txt檔案，裡面的中文件如下：<br /> [code]<br /> 第一筆...<br /> 年度號：70<br /> 分類號：0299<br /> 案次號：001<br /> <br /> 第二筆...<br /> 年度號：79<br /> 分類號：0299<br /> 案次號：011<br /> <br /> 第三筆...<br /> 年度號：78<br /> 分類號：0299<br /> 案次號：013<br /> [/code]<br /> 以上三筆資料。<br /> 錯誤訊息如下：<br /> [code]<br /> C:\JAVA_WORK\JAVA\HW\Jwork&gt;javac WriteFile.java<br /> WriteFile.java:52: cannot find symbol<br /> symbol  : variable node<br /> location: class WriteFile<br /> Signal += "年度號：" + node.getChildText("年度號")+lineSep+ "分類號：" + node.getChildText("分類號")+lineSep+ "案次號：" + node.getChildText("案次號")+lineSep;<br />                                             ^<br /> WriteFile.java:52: cannot find symbol<br /> symbol  : variable node<br /> location: class WriteFile<br /> Signal += "年度號：" + node.getChildText("年度號")+lineSep+ "分類號：" + node.getChildText("分類號")+lineSep+ "案次號：" + node.getChildText("案次號")+lineSep;<br />        ^<br /> WriteFile.java:52: cannot find symbol<br /> symbol  : variable node<br /> location: class WriteFile<br /> Signal += "年度號：" + node.getChildText("年度號")+lineSep+ "分類號：" + node.getChildText("分類號")+lineSep+ "案次號：" + node.getChildText("案次號")+lineSep;<br />                                                 ^<br /> 3 errors<br /> <br /> C:\JAVA_WORK\JAVA\HW\Jwork&gt;<br /> [/code]]]></description>
				<guid isPermaLink="true">http://www.andowson.com/posts/preList/572/1205.page</guid>
				<link>http://www.andowson.com/posts/preList/572/1205.page</link>
				<pubDate><![CDATA[Fri, 27 Jan 2012 13:40:26]]> GMT</pubDate>
				<author><![CDATA[ crc2121]]></author>
			</item>
			<item>
				<title>回覆:如何用程式寫出一個文字檔案，編碼為Big-5</title>
				<description><![CDATA[ [code]Signal += "年度號：" + node.getChildText("年度號")+lineSep+ "分類號：" + node.getChildText("分類號")+lineSep+ "案次號：" + node.getChildText("案次號")+lineSep;[/code]<br /> <br /> 區域變數 node 已超出使用範圍拉, 只能用在for回圈中!!<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.andowson.com/posts/preList/572/1206.page</guid>
				<link>http://www.andowson.com/posts/preList/572/1206.page</link>
				<pubDate><![CDATA[Thu, 2 Feb 2012 11:25:57]]> GMT</pubDate>
				<author><![CDATA[ bious3927]]></author>
			</item>
	</channel>
</rss>
