共 114篇 前 10 页: 10    每页5篇 下一页  

Java学习

sun rss2.0官方教程 [与之对应的中文教程]

Rss在java类中的解析过程:

package rss.parse;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;

import com.sun.cnpi.rss.elements.Channel;
import com.sun.cnpi.rss.elements.Item;
import com.sun.cnpi.rss.elements.Rss;
import com.sun.cnpi.rss.parser.RssParser;
import com.sun.cnpi.rss.parser.RssParserException;
import com.sun.cnpi.rss.parser.RssParserFactory;

public class RssTest {
 public static void main(String[] args){
  try {
   RssParser parser = RssParserFactory.createDefault();
   URL url = new URL("http://www.zhuoda.org/lunzi.rss");
   Rss rss = parser.parse(url);
   Channel channerl = rss.getChannel();
   System.out.println(channerl.getLink());
   System.out.println(channerl.getItems().size());
   System.out.println(channerl.getDescription());
   Iterator it = channerl.getItems().iterator();
   while(it.hasNext()){
    Item item = (Item) it.next();
    System.out.println("title:"+item.getTitle());
   }
  } catch (MalformedURLException e) {
   e.printStackTrace();
  } catch (RssParserException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

lunzi   2007-05-11 10:10:01 阅读:718  评论:0  引用:0
public static void main(String[] args){

    String foo = "[{"0":"12234107","1":"2012-01-27 12:59:36.227","2":"OXP","3":"CUCH-93717","4":"1","5":"CERRADA","6":"OXPD145","7":"2012-01-27 13:01:09.467","8":"UNACK_ALM"}]";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = null;
    HttpClient httpclient = null;
    HttpResponse response;
    System.out.println(foo.length());
        try {

                 httpclient = new DefaultHttpClient();
                 HttpPost httppost= new HttpPost ("http://127.0.0.1/lab/proyectos/php/java_envio_mensajes/post_json_gzip.php");
                 byte[] bgzip =  gzip(foo);
                 InputStreamEntity httpentity = new InputStreamEntity(new ByteArrayInputStream(bgzip), bgzip.length);
                 httpentity.setChunked(true);
                 httppost.setEntity(httpentity);
                 response=httpclient.execute(httppost);

                 httppost.setEntity(httpentity);

                ...
                }
}


public static byte[] gzip(String foo){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = null;

    try {
        gzos = new GZIPOutputStream(baos);
        gzos.write(foo.getBytes("UTF-8"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (gzos != null) try { gzos.close(); } catch (IOException ignore) {};
    }

    return baos.toByteArray();
}

转自:http://pastebin.com/bTTCHgRk
lunzi   2012-06-06 12:26:15 阅读:1102  评论:0  引用:0
http://edu.csdn.net/heima/heimaline.html?from=youxiang
lunzi   2012-02-26 18:47:55 阅读:274  评论:0  引用:0

package lunzi.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestExe {

/**
* @param args
*/

public static void main(String[] args) {
try {
// String[] cmd = new String[] { "F:/task/aapt.exe", "l -a
// F:/task/update/10-6-23/apk/4003373.apk >
// F:/task/update/10-6-23/apk/4003373.txt" };
// Process process = Runtime.getRuntime().exec(cmd,null,new
// File("F:/task/"));
String command =
"cmd /c start F:/task/task2010.6.24.bat";
// command ="F:/task/aapt.exe l -a
// F:/task/update/10-6-23/apk/4003373.apk >
// F:/task/update/10-6-23/apk/4003373.txt";

/*
* command = "/home/dingym/aapt d badging
* /home/dingym/YichaMarket.apk";
* System.out.println("------------start-------------");
* Runtime.getRuntime().exec(command);
* System.out.println("------------end---------------");
*/

/*
* BufferedReader r = new BufferedReader(new
* InputStreamReader(process .getErrorStream())); String l = null;
* while ((l = r.readLine()) != null) { System.out.println(l); }
*/


Runtime rt = Runtime.getRuntime();
System.out.println(
"------------start-test-------------");
String str[] = {
"/bin/sh", "-c", "./aapt d badging YichaMarket.apk" };
System.out.println(
"------------end-test---------------");
Process pcs = rt.exec(str);
BufferedReader br = new BufferedReader(new InputStreamReader(pcs
.getInputStream()));
String line = new String();
while ((line = br.readLine()) != null) {
System.out.println(line);
}
try {
pcs.waitFor();
} catch (InterruptedException e) {
System.err.println(
"processes was interrupted");
}
br.close();
int ret = pcs.exitValue();
System.out.println(ret);

} catch (Exception e) {
e.printStackTrace();
}
}

}

lunzi   2011-06-22 21:31:18 阅读:1291  评论:1  引用:0

package lunzi.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ConvertImei {

/**
* @param args
*/

public static void main(String[] args) {
convert(args);
}

private static void convert(String[] args) {
System.out.println(
"--------convetImei start----------------");
if (args.length<=0) {
return;
}

System.out.println(
"--------convetImei file="+args[0]+"----------------");

FileReader fr = null;
BufferedReader br = null;
FileWriter fw = null;
BufferedWriter bw = null;
Map<String,String> map = new HashMap<String,String>();
try {
fr = new FileReader(args[0]);
br = new BufferedReader(fr);
String line = null;
String[] filedArr = null;
String imei = null;
StringBuffer sb = new StringBuffer();
String txt = null;
while((line=br.readLine()) != null) {
filedArr = line.split(
" ");
imei = filedArr[4];
if (!
"null".equals(imei)) {
if (!map.containsKey(imei)) {
map.put(imei, Encrypt.Dencrypt(imei,
""));
}
System.out.println(Encrypt.Dencrypt(imei,
""));
}
sb.append(line).append(
"\n");
}

txt = sb.toString();
for(Map.Entry<String, String> entry:map.entrySet()){
            txt = txt.replaceAll(entry.getKey(), entry.getValue());
            System.out.println(
"--------entry.getKey()=>"+entry.getKey()+"----------entry.getValue()=>"+entry.getValue()+"+------");
     }

fw = new FileWriter(args[0]);
bw = new BufferedWriter(fw);
bw.write(txt);
bw.flush();
System.out.println(
"--------convetImei succful----------------");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fw != null) {
fw.close();
}
if (bw != null) {
bw.close();
}

if (fr != null) {
fr.close();
}

if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(
"--------convetImei end----------------");
}

}

lunzi   2011-06-01 19:18:35 阅读:521  评论:1  引用:0
http://hi.baidu.com/276598908/blog/item/02c0f0065487ff7002088183.html
lunzi   2011-05-28 13:20:49 阅读:256  评论:2  引用:0

package cn.yicha.sns.common.util;

import java.io.File;
import java.io.IOException;

public class DeleteSvnUtil {

public static void main(String[] args) {

File f = new File(
"E:\\workspace_yicha\\ws_2010\\gameCenter\\");

try {
showAllFiles(f);
} catch (Exception e) {
e.printStackTrace();
}
}

final static void showAllFiles(File dir) throws Exception {
File[] fs = dir.listFiles();
for (int i = 0; i < fs.length; i++) {
if (fs<i>.isDirectory()) {
try {

if (fs<i>.getName().equals(
".svn")) {
System.out.println(fs<i>.getAbsolutePath());
System.out.println(
"fileName:" + fs<i>.getName());
deleteDirectory(fs<i>);
} else {
System.out.println(
"not include .svn");
}
showAllFiles(fs<i>);
} catch (Exception e) {
}
}
}
}

static public void deleteDirectory(File dir) throws IOException {
if ((dir == null) || !dir.isDirectory()) {
throw new IllegalArgumentException(
"Argument " + dir+ " is not a directory. ");
}
File[] entries = dir.listFiles();
int sz = entries.length;
for (int i = 0; i < sz; i++) {
if (entries<i>.isDirectory()) {
deleteDirectory(entries<i>);
} else {
entries<i>.delete();
}
}
dir.delete();
}

}

lunzi   2010-11-15 16:56:05 阅读:657  评论:1  引用:0
@Test
public void testBooleanQuery2() {

Term t1 = new Term("content","绅士");
Term t2 = new Term("isValid","1");

TermQuery q1 = new TermQuery(t1);
TermQuery q2 = new TermQuery(t2);

BooleanQuery query = new BooleanQuery();
query.add(q1, Occur.MUST);
query.add(q2, Occur.MUST);

queryAndPrintResult(query);
}
lunzi   2010-08-30 22:34:08 阅读:510  评论:1  引用:0

1、要解析的reg.txt
<!--{&&nclude}-->


<!--
/*成功故事1 start--><a href="#">想创业吗?5月最热创业点子</a><!--成功故事1 end*/-->

<!--
/*成功故事1 start-->
  <a href="#">想创业吗?5月最热创业点子</a>
<!--成功故事1 end*/
-->

test
2、TestMain.java测试的java解析类
package org.openxtiger.regular.test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TestMain {

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new FileReader(
"e:/reg.txt"));
String temp =
"";
StringBuffer sb = new StringBuffer();
while((temp=br.readLine())!=null){
sb.append(temp+
"\r\n");
}
br.close();
System.out.println(sb.toString());

String str = sb.toString();
str = str.replaceAll(
"<!--\\{(.+?)\\}(.*?)-->", "<?php include(\"$1\") ?>");
str = str.replaceAll(
"<!--/\\*([\\s\\S]+?)\\*/-->","");
System.out.println(
"str="+str);

}

}

3、参考资料
lunzi   2009-09-22 01:10:49 阅读:2834  评论:1  引用:0

package org.openxtiger.threads.test;

public class ShareData implements Runnable {
private int i;
public void run() {
/*synchronized(ShareData.class){
while (i<10) {
i++;
System.out.println(Thread.currentThread().getName()+":"+i);
}
}*/

while (i<10) {
System.out.println(
"first="+Thread.currentThread().getName()+":"+i);
synchronized(ShareData.class){
//System.out.println(i);
i++;
//System.out.println(i);
for(int j=0;j<10000;j++);
System.out.println(Thread.currentThread().getName()+
":"+i);
}

}
}

public static void main(String[] args) {
ShareData s1 = new  ShareData();

Thread t1 = new Thread(s1);
Thread t2 = new Thread(s1);

t1.start();
t2.start();

}

}



这个线程是有问题的,猛一看没什么,多运行几次就会发现有i=11的数值输出,和while条件是i<10是想矛盾,刚开始我是百思不得其解,后来根据haohao提供的资料才搞明白,原来是synchronized保护块的问题,改成我上面被注释的那个synchronized包含块就可以了。

参考资料
lunzi   2009-06-18 14:38:31 阅读:633  评论:0  引用:0
Copyright@2004-2010 powered by YuLog