File file = new File("1.txt");
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String text = reader.readLine();
String s1="\u6df1\u6c34\u57d7";
String s2="深水埗";
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("2.txt"),"UTF-8");
out.write(text+s1+s2);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Sunday, March 27, 2011
Reading and saving UTF8 text file in Java
To read and save text file in Java, we need to add the "UTF-8" parameter in the Stream Reader.
Thursday, December 2, 2010
Capture standard output (stdout) in console command running at VBS
We can use WScript.Shell.Exec( ) and WScript.Shell.StdOut.ReadLine( ) to perform the task:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c dir")
strText=""
Do While Not objExecObject.StdOut.AtEndOfStream
strText = strText & objExecObject.StdOut.ReadLine() & chr(13)
Loop
Wscript.Echo strText
Sunday, October 10, 2010
Using X-Forward-For Header
Say if you have a web server on top of your application server, you can use "x-Forward-For" HTTP header in the application server to get the real IP of the client.
Note: Remote host only returns the IP of the web server instead.
Note: Remote host only returns the IP of the web server instead.
Sunday, September 20, 2009
Analyze JVM memory heap
To analyze how a Java web application is performed in terms of its memory usage, one can use Eclipse Memory Analyzer to do it.
Ref: Eclipse MAT
Ref: Eclipse MAT
Monday, July 13, 2009
InetAddress.getByName( ) cached result
java.net.InetAddress.getByName( ) will cached the result, even when the host name IP is changed. To fix this, issue the following option to Java VM:
-Dsun.net.inetaddr.ttl=0
It sets the timeout of the DNS cache to zero.
-Dsun.net.inetaddr.ttl=0
It sets the timeout of the DNS cache to zero.
Friday, September 26, 2008
Using netsh for IP config import/export
2 lines only:
netsh -c interface dump > filename
netsh -f filename
Ref: http://www.alibutt.com/?p=250
Some more about netsh to read at http://www.builderau.com.au/program/windows/print.htm?TYPE=story&AT=339272916-339024644t-320000994c
netsh -c interface dump > filename
netsh -f filename
Ref: http://www.alibutt.com/?p=250
Some more about netsh to read at http://www.builderau.com.au/program/windows/print.htm?TYPE=story&AT=339272916-339024644t-320000994c
Friday, August 29, 2008
What is COPM?
COPM = Computer Operation Procedures Manual
Saturday, August 2, 2008
How to check physical memory
1. winmsd.exe
2. pstat.exe (from resource kit)
3. memory.exe (http://www.savilltech.com/download/memory.zip)
From windowsitpro.com
2. pstat.exe (from resource kit)
3. memory.exe (http://www.savilltech.com/download/memory.zip)
From windowsitpro.com
Wednesday, April 16, 2008
Enable Java assertion
Just a soft reminder in case I want to use Java assertion. Given a class Cls:
> java -ea:Cls Cls
The comment will execute Cls which assertion enabled.
> java -ea:Cls Cls
The comment will execute Cls which assertion enabled.
Thursday, April 10, 2008
Remove system folder in windows explorer
Some program will create a system folder which could be viewed in your windows explorer. Sometimes when uninstalling the program, they cannot remove the system folder for you. To remove it, find those system folder are in:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
\CurrentVersion\Explorer\MyComputer\NameSpace\
References are from technospot
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
\CurrentVersion\Explorer\MyComputer\NameSpace\
References are from technospot
Subscribe to:
Posts (Atom)
CSP on Apache
To add CSP to root if sort of funny. The following will NOT work for most cases !! <LocationMatch "^/$"> Header s...
-
When Office2003 couldn't find file SKU011.CAB: regedit -> [HKEY_LOCAL_MACHINE] -> [SOFTWARE] -> [Microsoft] -> [Office] -...
-
The resolution can be changed by editing the BlueStack's registry: HKLM\SOFTWARE\BlueStacks\Guests\Android\FrameBuffer\0\Height and ...
-
Suppose you got a file in Big5 containing some HKSCS characters (e.g. 深水埗, 赤鱲角, etc). When your environment (Ref: Charset.defaultCharset( ) ...