??xml version="1.0" encoding="utf-8" standalone="yes"?> d《Java学习(fn)W记》,里面对对象容器的描述不错?/p> 1. ArrayList和LinkedList ArrayList使用?jin)数l结构实现List的数据。所以ArraryList用来快速定位对象是非常有效率的。但是如果要对ArraryList中间插入或者删除,效率?x)非怽?/p> LinkedList使用链表来实现的List。所以跟ArrayList相反QLinkedList对于插入和删除是非常有优势,反之对于快速定位,是LinkedList的弱V?/p> 1)ArrayListDemo 输出Q?/p>
2)用LinkedList实现的一个字W串?/p>
输出Q?/p>
今天想了(jin)一下,W一个要解决的问题就是上传一个Excel文gQ上传文件的lg到挺多的Q网上一搜,有一大堆教程Q但是现在ƈ不是要上传一个文件到服务器以作存储之用,而是要上传一个文件到内存里,以Java的数据结构存储v来,q检查,把合乎要求的数据写到数据库里。所以在|上的一大堆上传文g的组件ƈ不合用。于是又惌己写Q思\是从客L(fng)那里获取一个InputStreamQ然后就对这个InputStream做一pd的检查。代码如下:(x) l果的出d是如下(输出东西写到面Q:(x) Ҏ(gu)有用Q这个也正是我的文g里面的内容,其它的都是关于这些form的其它信息。对我这个程序是没有用的。如果这里写下去的话Q还要我d析那些是数据Q哪些是form的参数。好Q到现在为止Q我已经打消?jin)自己写的念头?jin)。我惻I那些lg都可以把上传文g装得那么好Q能不能利用那些库,抽出文g的IO,让我操作? buffalo.switchPart('body',url,false);如果url中包含汉字,是采用GBK~码的。在不改变tomcat的配|文件的情况下,在目标页面里获得url参数的正方法是 注意Q如果这里用utf-8作ؓ(f)~码的{换的话,?x)出Cؕ码?/p> 如果是post的话Q可以通过讄filter的方法来解决?/p> 如果是get或者是链接的话,以前是通过讄tomcat的配|文件server.xml来解决的Q但q样不好Qƈ不是所有的目Q我们都可以修改到服务器的tomcat的配|文件。具体代码如下:(x) q是觉得老方法管用,只是有点ȝ(ch):public class ArrayListDemo {
public static void main(String[] args) {
//用Scannerc,可以L获得commander的输?/span>
Scanner scanner = new Scanner(System.in);
List<String> list = new ArrayList<String>();
//在控制台输入Qquit退?/span>
while(true) {
System.out.print("Rokey@console# ");
String input = scanner.next();
if(input.equals("quit")) {
break;
}
list.add(input);
}
System.out.print("昄输入Q?);
//使用5.0的foreach功能对Listq行遍历
for(String s:list) {
//5.0的类C的输出格?/span>
System.out.printf("%s ",s);
}
}
}
Rokey@console# 一二三
Rokey@console# 三二一
Rokey@console# quit
昄输入Q一二三 三二一
/**
*
* @author Rokey
* 用LinkedList构徏一个字W栈Q先q先?/span>
*/
public class StringStack {
private LinkedList<String> linkList;
public StringStack() {
linkList = new LinkedList<String>();
}
public void push(String s) {
//元素加入链表第一个位|?/span>
linkList.addFirst(s);
}
public String pop() {
//删除链表W一个元素,q返?/span>
return linkList.removeFirst();
}
public String top() {
//q回链表W一个元素,但ƈ不删?/span>
return linkList.getFirst();
}
public boolean isEmpty() {
//(g)查链表是否ؓ(f)I?/span>
return linkList.isEmpty();
}
}
public class StringStackDemo {
public static void main(String[] args) {
//用Scannerc,可以L获得commander的输?/span>
Scanner scanner = new Scanner(System.in);
StringStack stack = new StringStack();
//在控制台输入Qquit退?/span>
while (true) {
System.out.print("Rokey@console# ");
String input = scanner.next();
if (input.equals("quit")) {
break;
}
stack.push(input);
}
System.out.print("昄输入Q?);
//使用5.0的foreach功能对Listq行遍历
while(!stack.isEmpty()) {
//5.0的类C的输出格?/span>
System.out.printf("%s ", stack.pop());
}
}
}
Rokey@console# 一二三
Rokey@console# 三二一
Rokey@console# quit
昄输入Q三二一 一二三
]]>
恩,Betty写的需求真有意思,考虑的问题很周全Q是一个很厉害的项目经理。如果从输入q里解决?jin)字W是否是半角的,那么Q以后的情况容易解军_多了(jin)。恩Q网上搜?jin)一下资料,查了(jin)一下书Q得Z(jin)以下代码Q?br />
String s1 = "123";
String s2 = "ab?/span>";
String s3 = "123ab?/span>";
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
for (int i = 0; i < s1.length(); i++) {
int j = s1.charAt(i);
if (j > 256) {
int temp = j - 65248;
if (temp >= 0) {
System.out.print((char)j+"-->:" + (char) temp);
} else {
System.out.print((char) j);
}
} else {
System.out.print((char) j);
}
}
System.out.println();
for (int i = 0; i < s2.length(); i++) {
int j = s2.charAt(i);
if (j > 256) {
int temp = j - 65248;
if (temp >= 0) {
System.out.print((char)j+"-->:" + (char) temp);
} else {
System.out.print((char) j);
}
} else {
System.out.print ((char) j);
}
}
System.out.println();
for (int i = 0; i < s3.length(); i++) {
int j = s3.charAt(i);
if (j > 256) {
int temp = j - 65248;
if (temp >= 0) {
System.out.print((char)j+"-->:" + (char) temp);
} else {
System.out.print((char) j);
}
} else {
System.out.print((char) j);
}
}
System.out.println();
}
?/span>-->a?/span>-->b?/span>--c
123?/span>-->a?/span>-->b?/span>--c
]]>ServletInputStream sis = request.getInputStream();
InputStreamReader isr = new InputStreamReader(sis);
int ch;
while((ch = isr.read()) != -1 ) {
out.println((char)ch);
}
System.out.flush();
-----------------------------7d7ea23120550
Content-Disposition: form-data; name="file1";
filename="C:\Documents and Settings\Administrator\桌面\test.txt"
Content-Type: text/plain
my name is Rokey.QԌkey。我的名字叫Rokey.
-----------------------------7d7ea23120550 Content-Disposition: form-data;
name="Submit" 上传 -----------------------------7d7ea23120550--
my name is Rokey.QԌkey。我的名字叫Rokey.
]]> 1: String name = new String(request.getParameter("name").getBytes(
2: "ISO8859-1"), "GBK");
1: Connector port="8080" maxHttpHeaderSize="8192"
2: maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
3: enableLookups="false" redirectPort="8443" acceptCount="100"
4: connectionTimeout="20000" disableUploadTimeout="true" uRIEncoding="gbk"/>
1: String id=new String(request.getParameter("id").getBytes("ISO8859-1"),"UTF-8");
2: String name = new String(request.getParameter("name").getBytes("ISO8859-1"),"UTF-8");
]]>
1: netsh interface ip set address name="本地q接" source=static addr=192.168.0.39
mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1
2: netsh interface ip set dns name = "本地q接" source = static addr = 202.116.128.1
3: netsh interface ip add dns name = "本地q接" addr = 202.116.128.2
如下写法是会(x)错误的,
造成的结果是 仔细留意?x)发现运通后面多?jin)一个空?/p>
必须Ҏ(gu)一下写法:(x)
注意</td>跟前面是没有I格的。这栯行结果就?x)是q样?a href="http://www.aygfsteel.com/images/blogjava_net/wonderer/WindowsLiveWriter/htmlTD_92F0/image_3.png" atomicselection="true"> Q是没有I格的?/p>
1QSpring支持包:(x)spring.jar , commons-logging.jar
2: JUnit支持包:(x) JUnit.jar
建立Beanc,
1: package refBeanDemo;
2:
3: import java.util.Date;
4:
5: public class HelloBean {
6: private String helloWorld;
7: private Date date;
8: public Date getDate() {
9: return date;
10: }
11: public void setDate(Date date) {
12: this.date = date;
13: }
14: public String getHelloWorld() {
15: return helloWorld;
16: }
17: public void setHelloWorld(String helloWorld) {
18: this.helloWorld = helloWorld;
19: }
20:
21: }
建立配置文gQ和在里面进行注?/p>
1: <?xml version="1.0" encoding="UTF-8"?>
2: <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "../resources/spring-beans-2.0.dtd" >
3: <beans>
4: <bean id="dateBean" class="java.util.Date"></bean>
5:
6: <bean id="helloBean" class="refBeanDemo.HelloBean">
7: <property name="helloWorld">
8: <value>你好Q世?span style="color: #0000ff"></value>
9: </property>
10: <property name="date" ref="dateBean"></property>
11: </bean>
12: </beans>
写JUnitq行试Q方便管理,把JUnit的东东放到test包里?/p>
1: package refBeanDemo;
2:
3: import org.springframework.context.ApplicationContext;
4: import org.springframework.context.support.ClassPathXmlApplicationContext;
5:
6: import junit.framework.TestCase;
7:
8: public class TestRefBeanDemo extends TestCase {
9: private ApplicationContext context;
10:
11: public void setUp() {
12: context = new ClassPathXmlApplicationContext("refBeanDemo/NewFile.xml");
13: }
14:
15: public void testSpring() {
16: HelloBean helloBean = (HelloBean)context.getBean("helloBean");
17: System.out.println(helloBean.getDate());
18: assertEquals("你好Q世?, helloBean.getHelloWorld());
19:
20: }
21: }
q行JUnit试
试成功。类的分布如下:(x)