
2006年10月31日
public class TestString {
public TestString() {
}
public static void main(String[] args) {
String s=new String("Hello");
modify(s);
System.out.println("s===="+s);
}
public static void modify(String s)
{
s+="world";
}
}
为什么是输出Hello,而不是Helloworld?
java里面会对 String ,int ,Integer 等基本类型,会用值进行传递,在modify 时会clone拷贝一副本在内存里面,但是打印出来的时候,还是按原来内容
其他Object类型,按照内存地址进行传递的,所以在modify 的时候会把值改掉,打印出来也会是“Hello world”
posted @
2006-10-31 16:46 野风 阅读(81) |
评论 (0) |
编辑 收藏
package com.xiewei.soft.text;
import java.util.TimerTask;
public class HelloWorldTask extends TimerTask{
public void run (){
System.out.print("Hello world");
}
}
package com.xiewei.soft.text;
import java.io.IOException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Fixed {
public static void main(String[] arg) throws IOException{
ApplicationContext ctx=new FileSystemXmlApplicationContext("JavaSource/conf/timetask.xml");
System.in.read();
}
}
然后在spring配置文件中插入
<beans>
<bean id ="helloWordTask" class="com.xiewei.soft.text.HelloWorldTask" />
<bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="delay">
<value>1000</value>
</property>
<property name="period">
<value>3000</value>
</property>
<property name="timerTask">
<ref local="helloWordTask"/>
</property>
</bean>
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref local="timerTask"/>
</list>
</property>
</bean>
</beans>
测试成功!!!!!!!
posted @
2006-10-31 15:18 野风 阅读(1152) |
评论 (1) |
编辑 收藏
/**
*
* 解析文件,取出URL地址
*
*/
public static void regexStr(){
String input="飞机但是http://mail.Sohu.com.cn飞机恺撒";
Pattern p = Pattern.compile("http://[*[a-zA-Z]|w{3}].*[a-zA-Z]");
Matcher m = p.matcher(input);
m.find();
String str=m.group();
System.out.print(str);
}
/**
* 根据URL,把网页保存到本地
* @param urlStr
* @param filename
* @return
*/
public static boolean getUrlToFileInputStream(String urlStr, String filename){
DataInputStream dataInputStream=null;
try{
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
dataInputStream = new DataInputStream(conn.getInputStream());
}catch(Exception e){
e.getMessage();
}
DataOutputStream dataoutputstream = null;
if(dataInputStream !=null){
try {
dataoutputstream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
byte b[] = new byte[1024*10];
int len = 0;
while ((len = dataInputStream.read(b, 0, 1024)) != -1) {
dataoutputstream.write(b, 0, len);
}
dataoutputstream.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}else{
return false;
}
}
posted @
2006-10-31 15:06 野风 阅读(691) |
评论 (1) |
编辑 收藏