摘要:
jxl是一个韩国人写的java操作excel的工具,在开源世界中,有两套比较有影响的API可供使用,一个是POI,一个是jExcelAPI。其中功能相对POI比较弱一点。但jExcelAPI对中文支持非常好,API是纯Java的,并不依赖Windows系统,即使运行在Linux下,它同样能够正确的处理Excel文件。另外需要说明的是,这套API对图形和图表的支持很有限,而且仅仅识别PNG格式。使用如下:搭建环境将下载后的文件解包,得到jxl.jar,放入classpath,安装就完成了。一、创建文件拟生成一个名为“test.xls”的Excel文件,其中第一个工作表被命名为“第一页”,大致效果 阅读全文
随笔分类 - Java功能代码(Java Function Code)
JAVA功能代码《13》----在Java中调整数组大小
2011-05-21 17:18 by java线程例子, 240 阅读, 收藏,
摘要:
13.在Java中调整数组大小public class resizeArray { /** * Reallocates an array with a new size, and copies the contents of the old * array to the new array. * * @param oldArray * the old array, to be reallocated. * @param newSize * the new array size. * @return A new array with ... 阅读全文
JAVA功能代码《12》----使用NIO快速复制文件
2011-05-21 17:15 by java线程例子, 238 阅读, 收藏,
摘要:
12.使用NIO快速复制文件public static void fileCopy(File in, File out) throws IOException { FileChannel inChannel = new FileInputStream(in).getChannel(); FileChannel outChannel = new FileOutputStream(out).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparent... 阅读全文
JAVA功能代码《11》----Java中将Array转换成Map
2011-05-21 17:14 by java线程例子, 320 阅读, 收藏,
摘要:
11.Java中将Array转换成Map下面是参考代码String[][] countries = { { "United States", "New York" }, { "United Kingdom", "London" }, { "Netherland", "Amsterdam" }, { "Japan", "Tokyo" }, { "France", "Paris" } }; Map c 阅读全文
JAVA功能代码《10》----Java获得目录列表
2011-05-20 17:50 by java线程例子, 136 阅读, 收藏,
摘要:
10.Java获得目录列表File dir = new File("directoryName"); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i = 0; i < children.length; i++) { // Get filename of file or directory String filename = children[i]; } }... 阅读全文
JAVA功能代码《9》----Java发送HTTP请求和提取数据
2011-05-20 17:49 by java线程例子, 172 阅读, 收藏,
摘要:
9.Java发送HTTP请求和提取数据try { URL my_url = new URL("www.baidu.com/"); BufferedReader br = new BufferedReader(new InputStreamReader(my_url .openStream())); String strTemp = ""; while (null != (strTemp = br.readLine())) { System.out.println(strTemp); } } catch (Exception ex) { ex.printS 阅读全文
JAVA功能代码《8》----Java创建图片的缩略图
2011-05-20 17:48 by java线程例子, 263 阅读, 收藏,
摘要:
8.Java创建图片的缩略图public void createThumbnail(String filename, int thumbWidth, int thumbHeight, int quality, String outFilename) throws InterruptedException, FileNotFoundException, IOException { // load image from filename Image image = Toolkit.getDefaultToolkit().getImage(filename); MediaTracker... 阅读全文
JAVA功能代码《7》----Java创建ZIP和JAR文件
2011-05-20 17:46 by java线程例子, 181 阅读, 收藏,
摘要:
7.Java创建ZIP和JAR文件if (args.length < 2) { System.err.println("usage: java ZipIt Zip.zip file1 file2 file3"); System.exit(-1); } File zipFile = new File(args[0]); if (zipFile.exists()) { System.err.println("Zip file already exists, please try another"); System.exit(-2); } FileOut 阅读全文
JAVA功能代码《6》----用Java实现屏幕截图
2011-05-20 17:39 by java线程例子, 239 阅读, 收藏,
摘要:
6.用Java实现屏幕截图import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Robot;import java.awt.Toolkit;import java.awt.image.BufferedImage;import java.io.File;import javax.imageio.ImageIO;/******************************************************************* * 用Java实现屏幕截图 * 该JavaBean可以直接在其他Jav 阅读全文
JAVA功能代码《5》----将Java中的util.Date转换成sql.Date
2011-05-19 16:32 by java线程例子, 217 阅读, 收藏,
摘要:
5.将Java中的util.Date转换成sql.Date这一片段显示如何将一个java util Date转换成sql Date用于数据库,代码如下:java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); 阅读全文
JAVA功能代码《4》----在Java中将String型转换成Date型
2011-05-19 16:22 by java线程例子, 192 阅读, 收藏,
摘要:
4.在Java中将String型转换成Date型SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = format.parse("2011-05-19 16:19:19"); } catch (ParseException e) { e.printStackTrace(); } 阅读全文
JAVA功能代码《3》----获取Java现在正调用的方法名
2011-05-19 16:13 by java线程例子, 172 阅读, 收藏,
摘要:
3.获取Java现在正调用的方法名String methodName = Thread.currentThread().getStackTrace()[1] .getMethodName(); 阅读全文
JAVA功能代码《2》----向文件中写入文本
2011-05-19 16:05 by java线程例子, 194 阅读, 收藏,
摘要:
2.向文件中写入文本BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter("filename", true)); out.write("aString"); } catch (IOException e) { // error processing code } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace()... 阅读全文
JAVA功能代码《1》----把Strings转换成int和把int转换成String
2011-05-19 15:44 by java线程例子, 256 阅读, 收藏,
摘要:
本文整理自网络,将为大家介绍开发人员非常有用的Java功能代码。这些代码,可以成为大家在今后的开发过程中,Java编程手册的重要部分。1. 把Strings转换成int和把int转换成StringString a = String.valueOf(2);//integer to numeric string int i = Integer.parseInt(a);//numeric string to an int 阅读全文