易截截图软件、单文件、免安装、纯绿色、仅160KB

java 生成xml文件

import java.awt.Image;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class createXml
{
public static boolean writeXml(String path,String dir,String wpath,String wname)
{
File[] files = ReaderListFiles(path);
boolean flag = false;
if(files!=null)
{
StringBuffer xml = ReaderFilesContent(files,dir);
if(xml!=null)
flag = writeXmlFile(wname,wpath,xml);
}

return flag;
}

private static File[] ReaderListFiles(String path)
{
File file = new File(path);
if(file.exists()&&file.isDirectory())
return file.listFiles();
else if(file.exists()&&file.isFile())
{
File[] files = new File[1];
files[0] = file;
return files;
}
else
return null;
}

private static StringBuffer ReaderFilesContent(File[] files,String dir)
{
StringBuffer txml = new StringBuffer();
for(int i=0;i<files.length;i++)
{
String filename = files[i].getName();
String temp = filename.substring(filename.lastIndexOf(".")+1);
if(temp!=null&&(temp.equals("gif")||temp.equals("jpg")||temp.equals("bmp")||temp.equals("jpeg")||temp.equals("png")))
txml.append(getImgDesc(filename,temp,dir,files[i]));
}
if(txml.length()>0)
{
StringBuffer xml = new StringBuffer("<?xml version='1.0' encoding='GBK'?>\r\n");
xml.append("<firstnode>\r\n");
xml.append(txml);
xml.append("</firstnode>");
return xml;
}
else
return null;
}

private static StringBuffer getImgDesc(String filename,String type,String dir,File file)
{
Image imgSrc;
StringBuffer xml = new StringBuffer();
try {
imgSrc = ImageIO.read(file);
int width = imgSrc.getWidth(null);
int height = imgSrc.getHeight(null);
xml.append("\t<secondnode id=\"").append(filename).append("\">\r\n");
xml.append("\t\t<name>").append(filename).append("</name>\r\n");


相关文档:

java上传


public boolean copy(String from, String to) {
  boolean temp=true;
  FileInputStream stream;
  try {
   stream = new FileInputStream(new File(from));
   FileOutputStream bos = new FileOutputStream(to);
   int bytesRea ......

Java中的中文排序(简短版)

在Java中,如果在对一个List或者Map排序,可以采用Collections的集合类中的sort方法来对List进行排序。至于map,可以使用TreeMap自动排序。
但以上排序仅仅是对英文排序时,才会正确,若果数据里面存在中文和英文时,那么排序就乱了。
现在我实现的方法是按照中文的拼音来排序。(网上,还有按笔画排序,在这里我就不一一 ......

关于JAVA的try catch finally的一个问题

class TestTryFinallyC {
public static void main(String[] args) {
System.out.println(testt());
}

public static int testt() {
int x = 99;
try {
return x;
}finally {
x = 8;
}
}
}

某年某月的某一天, ......

java读取xml文件

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ReadSetting {
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号