代码改变世界

Java格式化输出

2011-02-24 13:29 by RayLee, 388 阅读, 0 推荐, 收藏, 编辑
摘要:程序中常常遇见:控制数据格式化输出。而控制选项繁多,有时会忘记。该文做一个小结,作为以后参考引用。 整型数据(short, int等) %d A regular base-10 integer, such as 987 %o A base-8 octal integer, such as 1733 %x A base-16 lowercase hexadecimal integer, such a... 阅读全文

Java IO best practice

2011-02-23 21:24 by RayLee, 449 阅读, 0 推荐, 收藏, 编辑
摘要:A StreamCopier class that copies data between two streams as quickly as possible. The method reads from the input stream and writes onto the output stream until the input stream is exhausted. A 1K buf... 阅读全文

Java IO tips

2011-02-23 16:38 by RayLee, 273 阅读, 0 推荐, 收藏, 编辑
摘要:Java IO操作最常犯的错误是忘记关闭所操作的Stream。这些Stream是跟操作系统的资源(如文件,网络)联系在一起的,而操作系统的资源是有限的,如果不能正确释放,会导致其它程序不能正常工作。 是不是所有的Stream都需要调用close()方法释放资源?与文件,网络相关的Stream应该调用close()。byte array streams可以不用。 try { OutputStream... 阅读全文

Using java.util.Scanner to process line-based strings or files

2011-02-22 14:31 by RayLee, 233 阅读, 0 推荐, 收藏, 编辑
摘要:Scanner scanner = new Scanner(file or string); while (scanner.hasNextLine()) { processLine(scanner.nextLine()); } You can do more than that using Scanner. See details in Java API documentations. 阅读全文

移除SVN信息

2011-02-18 16:39 by RayLee, 374 阅读, 0 推荐, 收藏, 编辑
摘要:当平台基线版本升级后,需要把原有的应用程序移植到新的平台。如果你够幸运,平台升级不影响应用程序,你只需将原有程序拷贝到新的源码树下的正确位置。然后运行SVN的Add(or Add recursive),Commit将代码check in。 但运行SVN的Add命令会出问题,原因是在拷贝代码的同时也将原有的SVN信息拷贝了,它指向的是旧的SVN URL,而不是当前的SVN URL。所以你需要先删除... 阅读全文

关于相关"代理"模式的学习

2011-02-15 14:38 by RayLee, 237 阅读, 0 推荐, 收藏, 编辑
摘要:设计模式中有一类是跟代理相关的模式:Proxy, State, Facade, Adapter。初学者很容易混淆,不能明确它们的用途和区别。本文浅谈下它们的区别,以帮助更好的理解和运用。 Proxy 从例子可以看出,Proxy和Implementation同时实现了接口ProxyBase,真正的功能是由Implementation实例提供的。StateState模式提供统一的服务接口,而根据不... 阅读全文

Linux Find 命令精通指南

2011-01-20 14:41 by RayLee, 197 阅读, 0 推荐, 收藏, 编辑
摘要:http://www.oracle.com/technology/global/cn/pub/articles/calish-find.html 阅读全文

Dip and Sp

2011-01-18 13:42 by RayLee, 277 阅读, 0 推荐, 收藏, 编辑
摘要:Historically, programmers always designed computer interfaces in terms of pixels. For example, you might make a field 300 pixels wide, allow 5 pixels of spacing between columns, and define Icons 16-by... 阅读全文

Android Init Language

2011-01-12 10:27 by RayLee, 385 阅读, 0 推荐, 收藏, 编辑
摘要:本文来自Android源码文档,作为启动配置的一个指导。 The Android Init Language consists of four broad classes of statements, which are Actions, Commands, Services, and Options. All of these are line-oriented, consisting of t... 阅读全文

获得系统权限,修改系统时间 ---- 转

2011-01-04 16:39 by RayLee, 534 阅读, 1 推荐, 收藏, 编辑
摘要:Android中如何修改系统时间(应用程序获得系统权限) 在 android 的API中有提供 SystemClock.setCurrentTimeMillis()函数来修改系统时间,可惜无论你怎么调用这个函数都是没用的,无论模拟器还是真机,在logcat中总会得到"Unable to open alarm driver: Permission denied ".这个函数需要root权限或者运行与... 阅读全文