{
name:"myjson",
description:"it is my json",
display:function(arg){
alert(arg);
}
};
MyJson.display("json很简单");
link
powered by performancing firefox
powered by performancing firefox
function myfunc(){
alert("helloworld");
}
try{
if(myfunc)myfunc();
}catch(e)
{alert("exception");}
package jay.home.test.comm;
import static org.junit.Assert.*;
import java.io.InputStream;
import jay.home.test.dbunit.DBUnitUsage;
import org.junit.Test;
/**
* @author Jay
* @since 2006-9-20 下午12:02:15
*/
public class GetResourceAsStream
{
@Test
public void getResourceByClass()throws Exception
{
// 如果不是在同一目录下,不可访问到
InputStream stream2 = DBUnitUsage.class.getResourceAsStream("resource.file");
assertNull(stream2);
// 可以访问,需要加全限定名
InputStream stream3 = DBUnitUsage.class.getResourceAsStream("/jay/home/test/comm/resource.file");
assertNotNull(stream3);
// 可以访问,如果在同一个目录下就可以直接访问
InputStream stream4 = GetResourceAsStream.class.getResourceAsStream("resource.file");
assertNotNull(stream4);
}
@Test
public void getResourceByClassLoader() throws Exception
{
ClassLoader loader = GetResourceAsStream.class.getClassLoader();
InputStream stream1 = loader.getResourceAsStream("resource.file");
assertNull(stream1);
// 可以访问,加包名
InputStream stream2 = loader.getResourceAsStream("jay/home/test/comm/resource.file");
assertNotNull(stream2);
// 不可以访问,不需要最前的/
InputStream stream3 = loader.getResourceAsStream("/jay/home/test/comm/resource.file");
assertNull(stream3);
}
}
//这个字符串代表你的文件内容
String input = "A,1\nA,2\nA,3\nB,1\nB,2\nB,3\nB,4";
public void testCSDN()
{
Pattern pattern = Pattern.compile("[\n]+");
String[] results = pattern.split(input);
Map target = new HashMap();
//这里设置一个开始字符,也可以修改成察看文件获取
String current = "A";
ArrayList currentList = new ArrayList();
for(String item : results)
{
String[] currentLine = Pattern.compile("[,| ]+").split(item);
if(!current.equals(currentLine[0]))
{
target.put(current, currentList);
current = currentLine[0];
currentList = new ArrayList();
}
currentList.add(currentLine[1]);
}
target.put(current, currentList);
System.out.println(target);
}