<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ไอเอินบล๊อก &#187; Java</title>
	<atom:link href="http://www.iearn.in.th/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iearn.in.th</link>
	<description>Just Play and Just Knowledge</description>
	<lastBuildDate>Sat, 12 Jun 2010 06:40:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Java Communications API on Windows</title>
		<link>http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/</link>
		<comments>http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 15:11:21 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[comm]]></category>
		<category><![CDATA[java communication api]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[serial port]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=581</guid>
		<description><![CDATA[ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port นั้นเองโดยการใช้งานจึงต้องมีการใช้งาน Java Communication API สำหรับการติดต่อครับโดยใน windows XP จะทำการ set ดังนี้ 1. โหลดไฟล์ www.iearn.in.th/wp-download/commapi.rar 2. แตกไฟล์จะมีไฟล์ให้อ่านทำตามนั้นได้เลยครับ แต่หากว่าไม่ได้ลองอ่านตามผมก็ได้ครับ การ setup comm api 1. ให้ไปที่คุณได้ลง JDK ไว้ครับเช่นผมลงไว้ที่ C:\Program Files\Java\jdk1.6.0_14 2. นำเอาไฟล์ win32com.dll ไปไว้ที่ \jre\bin 3. นำเอาไฟล์ comm.jar ไปไว้ที่ \jre\lib\ext 4. นำเอาไฟล์ javax.comm.properties ไปไว้ทีท \jre\lib เป็นอันว่าสามารถเขียนโปรแกรมติดต่อ Serial Port ได้แล้วละครับ [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/09/java-comm-api.png"><img src="http://www.iearn.in.th/wp-content/uploads/2009/09/java-comm-api-300x148.png" alt="java-comm-api" title="java-comm-api" width="300" height="148" class="aligncenter size-medium wp-image-582" /></a><br />
ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port นั้นเองโดยการใช้งานจึงต้องมีการใช้งาน Java Communication API สำหรับการติดต่อครับโดยใน windows XP จะทำการ set ดังนี้<br />
<span id="more-581"></span><br />
1. โหลดไฟล์ www.iearn.in.th/wp-download/commapi.rar<br />
2. แตกไฟล์จะมีไฟล์ให้อ่านทำตามนั้นได้เลยครับ แต่หากว่าไม่ได้ลองอ่านตามผมก็ได้ครับ</p>
<p><strong>การ setup comm api</strong><br />
1. ให้ไปที่คุณได้ลง JDK ไว้ครับเช่นผมลงไว้ที่ C:\Program Files\Java\jdk1.6.0_14<br />
2. นำเอาไฟล์ win32com.dll ไปไว้ที่ \jre\bin<br />
3. นำเอาไฟล์ comm.jar ไปไว้ที่ \jre\lib\ext<br />
4. นำเอาไฟล์ javax.comm.properties ไปไว้ทีท \jre\lib</p>
<p>เป็นอันว่าสามารถเขียนโปรแกรมติดต่อ Serial Port ได้แล้วละครับ</p>
<p>ที่มา http://java.sun.com/products/javacomm/</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Basic Java Reflection and Inerface design for plugins</title>
		<link>http://www.iearn.in.th/2008/05/04/basic-java-reflection-and-inerface-design-for-plugins/</link>
		<comments>http://www.iearn.in.th/2008/05/04/basic-java-reflection-and-inerface-design-for-plugins/#comments</comments>
		<pubDate>Sun, 04 May 2008 12:25:47 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[A-Za-z]]></category>
		<category><![CDATA[DoubleSpace]]></category>
		<category><![CDATA[Inerface]]></category>
		<category><![CDATA[public interface]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[Reflections]]></category>
		<category><![CDATA[toUpperCase]]></category>

		<guid isPermaLink="false">http://www.jaideawhosting.com/nolifelover/?p=138</guid>
		<description><![CDATA[วันนี้อยากจะเขียนบล๊อกเกี่ยวกับที่ทำให้หมดครับเลยเอาโจทย์ข้อถัดมา มาแก้กันเลยครับ สำหรับโจทย์ข้อนี้จะมาเรียนรู้เรื่อง reflection ของ java กัน หากใครไม่ค่อยมีความรู้แนะนำบล๊อก Reflections on Java Reflection รับลองครับว่าเบื้องต้นทุกคนต้องเข้าใจแน่นอนครับ สำหรับโจทย์ที่ได้รับคือ จะมี folder สำหรับเก็บ plugins ของการ apply เพื่อใช้ร่วมกับข้อความที่เราต้องการโดยหากเราเอาไฟล์ .class ไปวางในโฟลเดอร์นั้น String ที่เราส่งค้าไปจะทำการเปลี่ยนสไตล์ตามที่เราตั้งไว้ใน plugins นั้นครับ โดยในที่นี้จะมี plugins 3 ไฟล์คือ DoubleSpace.class NonWordRemove.class UpperCase.class สำหรับในส่วนของการสร้าง interface สำหรับเพื่อให้ plugins ของเราสามารถเรียกใช้ได้พร้อมกัน package softwareskill; public interface PluginsInterface &#123; String Convert&#40;String senTence&#41;; &#125; ในส่วนของการเขียน plugins ทั้งหมดในการทำการแก้ไขลักษณะของ ตัวอักษรเราจะใช้ การ implement มาจาก [...]


Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
<li><a href='http://www.iearn.in.th/2010/04/23/text-shadow-on-ie-with-jquery-drop-shadow-plugins/' rel='bookmark' title='Permanent Link: text-shadow on ie with jquery drop shadow plugins'>text-shadow on ie with jquery drop shadow plugins</a> <small>สำหรับใครที่เคยใช้ css สำหรับสร้างเงานให้กับตัวอักษรนั้นหลายคนคงไม่ทราบว่าใน ie ไม่มี property นี้ครับ ผมก็ไม่เข้าใจเหมือนกันว่าทำไมว่า ie มันไม่ค่อยเหมือนชาวบ้านเท่าไร...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>วันนี้อยากจะเขียนบล๊อกเกี่ยวกับที่ทำให้หมดครับเลยเอาโจทย์ข้อถัดมา มาแก้กันเลยครับ สำหรับโจทย์ข้อนี้จะมาเรียนรู้เรื่อง reflection ของ java กัน หากใครไม่ค่อยมีความรู้แนะนำบล๊อก <a title="Permanent Link to Reflections on Java Reflection" rel="bookmark" href="http://www.devguli.com/blogs/trans/reflections_on_java_reflection/">Reflections on Java Reflection</a> รับลองครับว่าเบื้องต้นทุกคนต้องเข้าใจแน่นอนครับ สำหรับโจทย์ที่ได้รับคือ จะมี folder สำหรับเก็บ plugins ของการ apply เพื่อใช้ร่วมกับข้อความที่เราต้องการโดยหากเราเอาไฟล์ .class ไปวางในโฟลเดอร์นั้น String ที่เราส่งค้าไปจะทำการเปลี่ยนสไตล์ตามที่เราตั้งไว้ใน plugins นั้นครับ โดยในที่นี้จะมี plugins 3 ไฟล์คือ DoubleSpace.class NonWordRemove.class UpperCase.class สำหรับในส่วนของการสร้าง interface สำหรับเพื่อให้ plugins ของเราสามารถเรียกใช้ได้พร้อมกัน<br />
<span id="more-138"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">softwareskill</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> PluginsInterface <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> Convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> senTence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ในส่วนของการเขียน plugins ทั้งหมดในการทำการแก้ไขลักษณะของ ตัวอักษรเราจะใช้ การ implement มาจาก interface ที่เราเขียนขึ้น สำหรับโค้ด DoubleSpace เราสามารถเขียนได้ประมาณนี้ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DoubleSpace <span style="color: #000000; font-weight: bold;">implements</span> PluginsInterface<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> Convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> senTence<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> senTence.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span>, <span style="color: #0000ff;">&quot;  &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>จากโค้ดเมื่อเรา implemens PluginsInterface ผมจะทำการเขียน method convert ใหม่โดยให้เปลี่ยนจาก space bar เป้น double spacebar โดยการใช้ method replaceAll เพื่อทำการแทนค่าที่เจอด้วย space bar ครั้งตามที่เราต้องการ<br />
สำหรับโค้ดของ Uppercase จะเห็นว่าจะคล้ายๆกัน</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UpperCase <span style="color: #000000; font-weight: bold;">implements</span> PluginsInterface<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> Convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> senTence<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> senTence.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>และส่วนสุดท้ายคือหากไม่ใช่ตัวอักษรหรือตัวเลขให้ทำการตัดทิ้งไปครับ ในที่นี้ผมจะใช้ regular expression ที่ได้ทำการศึกษามาแล้วเมื่อบทความก่อนหน้า</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NonWordRemove <span style="color: #000000; font-weight: bold;">implements</span> PluginsInterface<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> Convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> senTence<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[^(A-Za-z0-9 ) ]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>senTence<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>สำหรับในส่วนของการนำไปใช้ก็จะเป็นโค้ดประมาณนี้นะครับโดยจะต้องมีการอ้าง path ที่ได้ทำการเก็บไฟล์ของ .class ที่ได้ผ่านการ compile มาแล้วครับ เพื่อจะนำ class ที่ได้ทั้งหมดมาใช้ครับซึ่งจะได้โค้ดประมาณนี้ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Reflection <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CLASSPATH<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/Users/mLri/NetBeansProjects/Softwareskill/build/classes/softwareskill/plugins&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        Reflection reflection <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Reflection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> output <span style="color: #339933;">=</span> reflection.<span style="color: #006633;">applyAllPlugins</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I love you G'meay,,,,,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> applyAllPlugins<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> plugIns <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getAllpluginClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i
&nbsp;
&nbsp;
ก้เป็นอันว่าเรียบร้อยครับสำหรับการทำโจทย์ในข้อนี้แต่หรับการ desiเื อาจะยังไม่ดีเท่าไรนะครับ หากใครมีอะไรแนะนำสามารที่จะแนะนำได้เลยนะครับ ขอบคุณครับ สามารถดูเรื่อง <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jaideawhosting.com/nolifelover/?p=126&quot;</span><span style="color: #339933;">&gt;</span>regular expression <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
<li><a href='http://www.iearn.in.th/2010/04/23/text-shadow-on-ie-with-jquery-drop-shadow-plugins/' rel='bookmark' title='Permanent Link: text-shadow on ie with jquery drop shadow plugins'>text-shadow on ie with jquery drop shadow plugins</a> <small>สำหรับใครที่เคยใช้ css สำหรับสร้างเงานให้กับตัวอักษรนั้นหลายคนคงไม่ทราบว่าใน ie ไม่มี property นี้ครับ ผมก็ไม่เข้าใจเหมือนกันว่าทำไมว่า ie มันไม่ค่อยเหมือนชาวบ้านเท่าไร...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2008/05/04/basic-java-reflection-and-inerface-design-for-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read File and check path</title>
		<link>http://www.iearn.in.th/2008/05/03/read-file-and-check-path/</link>
		<comments>http://www.iearn.in.th/2008/05/03/read-file-and-check-path/#comments</comments>
		<pubDate>Sat, 03 May 2008 06:24:24 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[BufferedReader]]></category>
		<category><![CDATA[lineBuffer]]></category>
		<category><![CDATA[read file]]></category>
		<category><![CDATA[write file]]></category>

		<guid isPermaLink="false">http://www.jaideawhosting.com/nolifelover/?p=137</guid>
		<description><![CDATA[หลังจากหายหน้าหายตาไปหลายวันไม่ได้ไปไหนนะครับแต่ว่าช่วงนี้งานส่วนของ Asterisk ที่เน้น ruby เป็นหลังต้องทำให้ค้องแบ่งเวลาในการเขียนบล๊อกทั้งหมดไปทำในส่วนนี้สำหรับวันที่วันเสาร์เรียน scjp เสร็จเลยมีอารมณ์อยากที่จะเขียนบล๊อก่อจากวันก่อนครับ สำหรับวันนี้จะเขียนเกี่ยวกับโค้ดของ softskill ต่อละกันนะครับ สำหรับวันนี้โจทย์จะเป็นไปในลักษณะให้เราอ่าน ไฟล์จาก input.txt ซึ่งมี path ของ file อยู่และให้อ่านอีกไฟล์คือไฟล์ rules.txt เพื่อทำการตวรจสอบว่าไฟล์นั้นผ่านกฏต่างๆ ที่ได้กำหนดไว้ในไฟล์ rules.txt หรือไม่หากว่าตรงให้เอาเฉพาะไฟล์ที่อณุญาตเท่านั้นครับ เรามาดูกันเลยดีกว่าครับ โดยในที่นี้ผมจะใช้ Pathmanager ที่ได้เขียนไว้ในการจัดการเรื่อง permission ครับ สำหรับไฟล์ใหม่ที่เขียนขึ้นตามนี้ครับ package softwareskill; &#160; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; &#160; /** * * @author mLri */ public [...]


Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
<li><a href='http://www.iearn.in.th/2009/08/23/set-path-on-ubuntu/' rel='bookmark' title='Permanent Link: Set Path On Ubuntu'>Set Path On Ubuntu</a> <small>สำหรับบทความนี้เป็นวิธีการ set path ใน ubuntu สำหรับคนที่ยังทำไม่ค่อยจะเป็นนะครับวิธีการมี 2 วิธีคือการเปิด terminal มาแล้ว...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>หลังจากหายหน้าหายตาไปหลายวันไม่ได้ไปไหนนะครับแต่ว่าช่วงนี้งานส่วนของ Asterisk ที่เน้น ruby เป็นหลังต้องทำให้ค้องแบ่งเวลาในการเขียนบล๊อกทั้งหมดไปทำในส่วนนี้สำหรับวันที่วันเสาร์เรียน scjp เสร็จเลยมีอารมณ์อยากที่จะเขียนบล๊อก่อจากวันก่อนครับ สำหรับวันนี้จะเขียนเกี่ยวกับโค้ดของ softskill ต่อละกันนะครับ สำหรับวันนี้โจทย์จะเป็นไปในลักษณะให้เราอ่าน ไฟล์จาก input.txt ซึ่งมี path ของ file อยู่และให้อ่านอีกไฟล์คือไฟล์ rules.txt เพื่อทำการตวรจสอบว่าไฟล์นั้นผ่านกฏต่างๆ ที่ได้กำหนดไว้ในไฟล์ rules.txt หรือไม่หากว่าตรงให้เอาเฉพาะไฟล์ที่อณุญาตเท่านั้นครับ เรามาดูกันเลยดีกว่าครับ โดยในที่นี้ผมจะใช้ Pathmanager ที่ได้เขียนไว้ในการจัดการเรื่อง permission ครับ สำหรับไฟล์ใหม่ที่เขียนขึ้นตามนี้ครับ</p>
<p><span id="more-137"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">softwareskill</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileNotFoundException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileWriter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author mLri
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SecueManager <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> rule<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> input<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> output<span style="color: #339933;">;</span>
    PathManager pathManager<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        SecueManager secueManager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span>  SecueManager<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/Users/mLri/rule.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        secueManager.<span style="color: #006633;">processFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/Users/mLri/input.txt&quot;</span>, <span style="color: #0000ff;">&quot;/Users/mLri/output.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> SecueManager<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> rule<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">rule</span> <span style="color: #339933;">=</span> rule<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">pathManager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PathManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">readRule</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> processFile<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input,<span style="color: #003399;">String</span> output<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">input</span> <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">output</span> <span style="color: #339933;">=</span> output<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">pathProcess</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> readRule<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>rule<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">BufferedReader</span> fileBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> lineBuffer<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lineBuffer <span style="color: #339933;">=</span> fileBuffer.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lineBuffer.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                pathManager.<span style="color: #006633;">addAcceptedRule</span><span style="color: #009900;">&#40;</span>lineBuffer.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;is complete addAcceptRule is &quot; + lineBuffer.substring(1));</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lineBuffer.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;-&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                pathManager.<span style="color: #006633;">addDeniedRule</span><span style="color: #009900;">&#40;</span>lineBuffer.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;is complete addDeniedRule is &quot; + lineBuffer.substring(1));</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        fileBuffer.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;readRule is Successful&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> pathProcess<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">BufferedReader</span> fileBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">ArrayList</span> allowFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> lineBuffer<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lineBuffer <span style="color: #339933;">=</span> fileBuffer.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pathManager.<span style="color: #006633;">isAllow</span><span style="color: #009900;">&#40;</span>lineBuffer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;add line &quot; + lineBuffer);</span>
                allowFile.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>lineBuffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        fileBuffer.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">pathWrite</span><span style="color: #009900;">&#40;</span>allowFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> pathWrite<span style="color: #009900;">&#40;</span><span style="color: #003399;">ArrayList</span> allowFile<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">FileWriter</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileWriter</span><span style="color: #009900;">&#40;</span>output,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> accept<span style="color: #339933;">:</span>allowFile<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            file.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>accept<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        file.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File output is Suscessful in &quot;</span><span style="color: #339933;">+</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>สำหรับไฟล์ SecueManager จะเป็นตัวที่ทำหน้าที่ในการอ่านไฟล์และเขียนไฟล์ ส่วนไฟล์ที่ทำการ check จริงๆจะเป็นไฟล์ <a href="http://www.jaideawhosting.com/nolifelover/?p=126">PathManager</a> ครับ</p>


<p>Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
<li><a href='http://www.iearn.in.th/2009/08/23/set-path-on-ubuntu/' rel='bookmark' title='Permanent Link: Set Path On Ubuntu'>Set Path On Ubuntu</a> <small>สำหรับบทความนี้เป็นวิธีการ set path ใน ubuntu สำหรับคนที่ยังทำไม่ค่อยจะเป็นนะครับวิธีการมี 2 วิธีคือการเปิด terminal มาแล้ว...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2008/05/03/read-file-and-check-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File permission with regular expression</title>
		<link>http://www.iearn.in.th/2008/04/25/file-permission-with-regular-expression/</link>
		<comments>http://www.iearn.in.th/2008/04/25/file-permission-with-regular-expression/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 11:37:30 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[Hashset]]></category>
		<category><![CDATA[mLri]]></category>
		<category><![CDATA[pathManager]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[softwareskill]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.jaideawhosting.com/nolifelover/?p=126</guid>
		<description><![CDATA[สำหรับโจทย์ในวันนี้ืคือการเขียนโปรแกรมต่อจากของเมื่อวานเกี่ยวกับการตวจสอบ permission ของ file ว่าเราสามารถ access เข้าใช้ได้หรือไม่โดย หากตรงกับกฏของการ denied ให้ทำการ denied เลย แต่หากไม่ตรงก็ให้ทำการตวจสอบว่าสามารถเข้าใช้ได้หรือไม่ ครับโดยมี source code สำหรับข้อนี้เป็นโจทย์มาให้คือ 1 2 3 4 5 6 7 8 9 10  public static void main&#40;String&#91;&#93; args&#41;  &#123;   PathManager pathManager = new PathManager&#40;&#41;;   pathManager.addDeniedRule&#40;&#34;\\w.*\\.exe$&#34;&#41;;   pathManager.addAcceptedRule&#40;&#34;^\\d&#34;&#41;;   if&#40;pathMananager.isAllow&#40;&#34;c:/temp/12.exe&#34;&#41;&#41;   System.out.println&#40;&#34;accepted&#34;&#41;;   else   System.out.println&#40;&#34;denied&#34;&#41;;  &#125; สำหรับกฏต่างๆ user สามารถเขียน [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>สำหรับโจทย์ในวันนี้ืคือการเขียนโปรแกรมต่อจากของเมื่อวานเกี่ยวกับการตวจสอบ permission ของ file ว่าเราสามารถ access เข้าใช้ได้หรือไม่โดย หากตรงกับกฏของการ denied ให้ทำการ denied เลย แต่หากไม่ตรงก็ให้ทำการตวจสอบว่าสามารถเข้าใช้ได้หรือไม่ ครับโดยมี source code สำหรับข้อนี้เป็นโจทย์มาให้คือ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 	PathManager pathManager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PathManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	pathManager.<span style="color: #006633;">addDeniedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>w.*<span style="color: #000099; font-weight: bold;">\\</span>.exe$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	pathManager.<span style="color: #006633;">addAcceptedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>pathMananager.<span style="color: #006633;">isAllow</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c:/temp/12.exe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;accepted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #000000; font-weight: bold;">else</span>
 		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;denied&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-126"></span></p>
<p>สำหรับกฏต่างๆ user สามารถเขียน method เพื่ีอ add rule ไปได้เรื่อยๆ ครับ สำหรับการเขียนของผมในวันนี้ใช้เรื่องของ Hashset, regular expression เบื้องต้น และใช้ method String.matches(String reg) เพื่อตรวจสอบว่าตรงกับ regular expression ที่เราต้องการหรือไม่ สำหรับโค้ดที่ได้ประมาณนี้ครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">softwareskill</span><span style="color: #339933;">;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashSet</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author mLri
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PathManager <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//field</span>
    <span style="color: #003399;">HashSet</span> deniedRule<span style="color: #339933;">;</span>
    <span style="color: #003399;">HashSet</span> acceptedRule<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PathManager pathManager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PathManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        pathManager.<span style="color: #006633;">addDeniedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>w*<span style="color: #000099; font-weight: bold;">\\</span>.exe$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        pathManager.<span style="color: #006633;">addDeniedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>w*<span style="color: #000099; font-weight: bold;">\\</span>.bat$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        pathManager.<span style="color: #006633;">addDeniedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>w*<span style="color: #000099; font-weight: bold;">\\</span>.msi$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        pathManager.<span style="color: #006633;">addAcceptedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>d.*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        pathManager.<span style="color: #006633;">addAcceptedRule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>w*(<span style="color: #000099; font-weight: bold;">\\</span>.jpg||<span style="color: #000099; font-weight: bold;">\\</span>.pdf||<span style="color: #000099; font-weight: bold;">\\</span>.png)$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//pathManager.addAcceptedRule(&quot;\\w*\\.png$&quot;);</span>
        <span style="color: #666666; font-style: italic;">//pathManager.addAcceptedRule(&quot;\\w*\\.pdf$&quot;);</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pathManager.<span style="color: #006633;">isAllow</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c:/tem/2aaa.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;accepted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;denied&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> PathManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">deniedRule</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">acceptedRule</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> addDeniedRule<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> exp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">deniedRule</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>exp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> addAcceptedRule<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> exp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">acceptedRule</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>exp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isAllow<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> tmp <span style="color: #339933;">=</span> file.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tmp <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            file <span style="color: #339933;">=</span> tmp<span style="color: #009900;">&#91;</span>tmp.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">checkDeniedRule</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">checkAcceptRule</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> checkAcceptRule<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>acceptedRule.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> rule <span style="color: #339933;">:</span> acceptedRule<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;file is &quot; + file);</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;rule is &quot; + rule);</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>rule<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">//System.out.println(&quot;rule is accepted&quot;);</span>
                    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> checkDeniedRule<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>deniedRule.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> rule <span style="color: #339933;">:</span> deniedRule<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;file is &quot; + file);</span>
                <span style="color: #666666; font-style: italic;">//System.out.println(&quot;rule is &quot; + rule);</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>rule<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">//System.out.println(&quot;rule is denied&quot;);</span>
                    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>HashSet คือ class ประมาณเดียวกับ Array สามารถเช็คการซำ้กันของสมาชิกได้หากซ้ำกันจะไม่ Add เพิ่มลงไปครับ<br />
Regular Expression คือสมการที่ใช้ในการตรวจสอบรูปแบบ format ของ string ว่าตรงตามที่เราต้องการหรือไม่โดยจะสามารถนำไปใช้ในการตรวจสอบ email การอัพโหลดไฟล์ ชนิดของไฟล์ประมาณนั้นครับ<br />
<a href="http://www.amk.ca/python/howto/regex/">http://www.amk.ca/python/howto/regex/</a><br />
<a href="http://www.aprelium.com/abyssws/articles/regex-basics.html">http://www.aprelium.com/abyssws/articles/regex-basics.html</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2008/04/25/file-permission-with-regular-expression/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java covert Linux path to Windows path</title>
		<link>http://www.iearn.in.th/2008/04/24/java-covert-linux-path-to-windows-path/</link>
		<comments>http://www.iearn.in.th/2008/04/24/java-covert-linux-path-to-windows-path/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 15:53:43 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[convertWindowsPath]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[linuxPath]]></category>
		<category><![CDATA[pathConfig]]></category>
		<category><![CDATA[PathReplace]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[windowsPath]]></category>

		<guid isPermaLink="false">http://www.jaideawhosting.com/nolifelover/?p=123</guid>
		<description><![CDATA[สำหรับช่วงนี้ห้องผมจะมีโจทย์จากกอาจาร์มาประมาณ 1 ข้อต่อวันครับเพื่อฝึกทักษะการเขียนโปรแกรมของพวกเราหลังจากที่ ได้เขียน Android Application ไม่เข้าตากรรมการ สำหรับโจทย์วันแรกคือการเขียนเจ้า Java เพื่อแปลง path ของ linux ไปเป็น windows ครับ เราดูโจทย์กันดีกว่าครับ input /home/user/images/xxx.jpg config /home/user =&#62; c:\user output c:\user\images\xxx.jpg โดยเจ้าโปรแกรมที่เขียนต้องสามารถ maintain และ reuse ได้โดยเจ้าโปรแกรมที่เขียนได้ประมาณนี้ครับ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [...]


Related posts:<ol><li><a href='http://www.iearn.in.th/2009/08/23/set-path-on-ubuntu/' rel='bookmark' title='Permanent Link: Set Path On Ubuntu'>Set Path On Ubuntu</a> <small>สำหรับบทความนี้เป็นวิธีการ set path ใน ubuntu สำหรับคนที่ยังทำไม่ค่อยจะเป็นนะครับวิธีการมี 2 วิธีคือการเปิด terminal มาแล้ว...</small></li>
<li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>สำหรับช่วงนี้ห้องผมจะมีโจทย์จากกอาจาร์มาประมาณ 1 ข้อต่อวันครับเพื่อฝึกทักษะการเขียนโปรแกรมของพวกเราหลังจากที่ ได้เขียน Android Application ไม่เข้าตากรรมการ สำหรับโจทย์วันแรกคือการเขียนเจ้า Java เพื่อแปลง path ของ linux ไปเป็น windows ครับ เราดูโจทย์กันดีกว่าครับ</p>
<p>input /home/user/images/xxx.jpg<br />
config /home/user =&gt; c:\user<br />
output c:\user\images\xxx.jpg</p>
<p><span id="more-123"></span></p>
<p>โดยเจ้าโปรแกรมที่เขียนต้องสามารถ maintain และ reuse ได้โดยเจ้าโปรแกรมที่เขียนได้ประมาณนี้ครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */</span>
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">softwareskill</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author mLri
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> PathReplace <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #003399;">String</span> windowsPath<span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> linuxPath<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PathReplace path <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PathReplace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c:<span style="color: #000099; font-weight: bold;">\\</span>thai&quot;</span>, <span style="color: #0000ff;">&quot;/home/new&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> testPath <span style="color: #339933;">=</span> path.<span style="color: #006633;">parsePath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/home/new/images/xxx.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testPath is &quot;</span><span style="color: #339933;">+</span>testPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> PathReplace<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pathConfig, <span style="color: #003399;">String</span> pathConvertTo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        windowsPath <span style="color: #339933;">=</span> pathConfig<span style="color: #339933;">;</span>
        linuxPath <span style="color: #339933;">=</span> pathConvertTo<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> parsePath<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> newPath <span style="color: #339933;">=</span> path.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span>linuxPath, windowsPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> convertWindowsPath <span style="color: #339933;">=</span> newPath.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span>,<span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//System.out.println(&quot;newPath is &quot; + newPath);</span>
        <span style="color: #666666; font-style: italic;">//System.out.println(&quot;windowsPath is &quot;+windowsPath);</span>
        <span style="color: #000000; font-weight: bold;">return</span> convertWindowsPath<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>Related posts:<ol><li><a href='http://www.iearn.in.th/2009/08/23/set-path-on-ubuntu/' rel='bookmark' title='Permanent Link: Set Path On Ubuntu'>Set Path On Ubuntu</a> <small>สำหรับบทความนี้เป็นวิธีการ set path ใน ubuntu สำหรับคนที่ยังทำไม่ค่อยจะเป็นนะครับวิธีการมี 2 วิธีคือการเปิด terminal มาแล้ว...</small></li>
<li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2008/04/24/java-covert-linux-path-to-windows-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เริ่มต้นกับ iReport  Support UTF8</title>
		<link>http://www.iearn.in.th/2007/11/26/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-ireport-support-utf8/</link>
		<comments>http://www.iearn.in.th/2007/11/26/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-ireport-support-utf8/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 08:54:12 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[iReport]]></category>
		<category><![CDATA[JasperReport]]></category>

		<guid isPermaLink="false">http://www.jaideaw.com/nolifelover/?p=51</guid>
		<description><![CDATA[??? ตอนนี้ผมกำลังศึกษาการสร้าง Report ด้วยภาษา Java ซึ่งมีหลาย Tool ที่เราสามารถใช้ได้ตอนแรกก็ว่าอยากจะใช้ Crystal Report แต่ดันเป็นของเสียเงินเลย หา Tool ตัวใหม่ไปเจอ JasperResport ซึ่งสามารถใช้งานร่วมกับ Java ได้แต่ปัญหาคือว่าเมื่อเราใช้แล้วเราต้องเขียนโค้ดเองหมดเลยหรือ จึงนั่งซักพักก็พบ Tool อีกตัวเหมาะสำหรับ JasperReport เบยชื่อว่า iReport เลยจับลองมาทำดูแต่พอทำไปทำมาประสบปัญหาเรื่องของภาษาไทย พอมีวิธีแก้เลยเ้อามาแนะนำกันครับ เนื่องจากปัจจุบัน Databases ส่วนมากจะ Encode เป็น UTF-8 ดังนั้นในขั้นตอนของการเรียก URL ในการ connect ต้องเป็นการเพิ่ม Option ที่เรียกแบบ UTF-8 ด้วยดังนี้ครับ jdbc:mysql://localhost:3306/myproject?charectorEncoding=UTF-8? แค่นี้ก็หมดปัญหาเรื่องภาษาไทยละหลังจากนี้หากมีบทความเรื่อง Jasper Report&#38;iReport ผมก็จะนำมาฝากไว้ที่นี้นะครับ Related posts:Java Communications API on Windows ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID [...]


Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>??? ตอนนี้ผมกำลังศึกษาการสร้าง Report ด้วยภาษา Java ซึ่งมีหลาย Tool ที่เราสามารถใช้ได้ตอนแรกก็ว่าอยากจะใช้ Crystal Report แต่ดันเป็นของเสียเงินเลย หา Tool ตัวใหม่ไปเจอ JasperResport ซึ่งสามารถใช้งานร่วมกับ Java ได้แต่ปัญหาคือว่าเมื่อเราใช้แล้วเราต้องเขียนโค้ดเองหมดเลยหรือ จึงนั่งซักพักก็พบ Tool อีกตัวเหมาะสำหรับ JasperReport เบยชื่อว่า iReport เลยจับลองมาทำดูแต่พอทำไปทำมาประสบปัญหาเรื่องของภาษาไทย พอมีวิธีแก้เลยเ้อามาแนะนำกันครับ</p>
<p>เนื่องจากปัจจุบัน Databases ส่วนมากจะ Encode เป็น UTF-8 ดังนั้นในขั้นตอนของการเรียก URL ในการ connect ต้องเป็นการเพิ่ม Option ที่เรียกแบบ UTF-8 ด้วยดังนี้ครับ</p>
<p>jdbc:mysql://localhost:3306/myproject?charectorEncoding=UTF-8? แค่นี้ก็หมดปัญหาเรื่องภาษาไทยละหลังจากนี้หากมีบทความเรื่อง Jasper Report&amp;iReport ผมก็จะนำมาฝากไว้ที่นี้นะครับ</p>


<p>Related posts:<ol><li><a href='http://www.iearn.in.th/2009/09/01/java-communications-api-on-windows/' rel='bookmark' title='Permanent Link: Java Communications API on Windows'>Java Communications API on Windows</a> <small>ผมเปลี่ยนโปรแจคมาทำเรื่องเกี่ยวกะ การอ่าน RFID โดยการติดต่อจะเขียนโปรแกรมโดยใช้ Java จึงจำเป็นต้องรู้เรื่องของการอ่านข้อมูลมากจาก RS232 หรือว่า Serial Port...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2007/11/26/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-ireport-support-utf8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
