7월, 2013의 게시물 표시

android cache 사용하기

android cache 사용하기
---------------------------------------------------



import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;
public class CacheStorage {
private static String _cacheFileName = "cache";
private static Context Ctx;

public CacheStorage(Context ctx, String cacheFileName){
if(cacheFileName != null && cacheFileName.length() > 0)
_cacheFileName = cacheFileName;
}

public void setCacheFile(String data) throws IOException{
setCacheFile( _cacheFileName, data);
}

public void setCacheFile(String cacheFileName, String data) throws IOException{

if(cacheFileName == null || cacheFileName.length() < 1) cacheFileName = _cacheFileName;

try {
File cacheDir = Ctx.getCacheDir();
        File cacheFile = new File(cacheDir.getAbsolutePath(), cacheFileName);
        FileOutputStream fos;

fos =…

[java] RSS-뉴스 읽기

다음 뉴스 RSS [ http://media.daum.net/rss/today/primary/all/rss2.xml ]

--------[ source code ]-------------
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class GetRSS {

/**
* @param args
*/
public static void main(String[] args) {
String rssUrl = "http://media.daum.net/rss/today/primary/all/rss2.xml";

try {
parseXml(rssUrl);
} catch (Exception e) {
e.printStackTrace();
}
}



private static void parseXml(String _url) throws Exception{
System.out.println("parse XML");

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(_url);

doc.getDocumentElement().normalize();

NodeList itemNodeList = doc.getElementsByTagName("item");

System.out.println("count :"  + itemNodeList.getLength());
for(int i =0; i < itemNodeList.getLength(); i++…

[java] xml파싱하기

private static void parseXml(String _url) throws Exception{
        System.out.println("parse XML");

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(_url);

        doc.getDocumentElement().normalize();

        NodeList itemNodeList = doc.getElementsByTagName("item");

        System.out.println("count :"  + itemNodeList.getLength());
        for(int i =0; i < itemNodeList.getLength(); i++){
            Node itemNode = itemNodeList.item(i);

            if(itemNode.getNodeType() == Node.ELEMENT_NODE){
                Element itemElement = (Element)itemNode;

                NodeList titleNodeList = itemElement.getElementsByTagName("title"); 
                Element titleElement = (Element)titleNodeList.item(0); 
                NodeList childTitleNodeList = titleElement.getChildNodes(); 
                System.out.printf("[title : %s]\n"…