易截截图软件、单文件、免安装、纯绿色、仅160KB

Java读写txt文件

 笔试的时候想不起来怎么写了。留个代码作纪念
package common;
import java.io.*;
import java.util.ArrayList;
public class IOTest {
public static void main (String args[]) {

ReadDate();

WriteDate();

}

/**
* 读取数据
*/
public static void ReadDate() {
String url = "e:/2.txt";
try {
FileReader read = new FileReader(new File(url));
StringBuffer sb = new StringBuffer();
char ch[] = new char[1024];
int d = read.read(ch);
while(d!=-1){
String str = new String(ch,0,d);
sb.append(str);
d = read.read(ch);
}
System.out.print(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 写入数据
*/
public static void WriteDate() {

try{
File file = new File("D:/abc.txt");
if (file.exists()) {

file.delete();
}

file.createNewFile();

BufferedWriter output = new BufferedWriter(new FileWriter(file));

ArrayList ResolveList = new ArrayList();

for (int i = 0; i < 10; i++) {

ResolveList.add(Math.random()* 100);

}

for (int i=0 ;i<ResolveList.size(); i++) {
output.write(String.valueOf(ResolveList.get(i)) + "\n");
}
output.close();
} catch (Exception ex) {
System.out.println(ex);
}

}
}


相关文档:

jakarta regexp (java struts正则表达式)


  Character Classes
      [abc]                  Simple character class
      [a-zA-Z]            ......

Java Application 直接通过jndi连接数据库

 使用jar包:
 commons-pool-1.5.3.jar,tomcat-naming-common.jar,commons-pool-1.5.3-bin.zip,commons-dbcp.jar
 注意:jdbc 驱动要与数据库兼容.
 package test.comm;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.naming.InitialCont ......

java中的String池

 
 
在进入我们今天的话题前,先来看看下面这段代码,你知道它的结果吗?
程序代码
public class StringTest1{
  public static void main(String[] args) {
     String str1 = "abc";
     String str2 = "abc";
   &nbs ......

Java多线程程序设计详细解析

  一、理解多线程
  多线程是这样一种机制,它允许在程序中并发执行多个指令流,每个指令流都称为一个线程,彼此间互相独立。
  线程又称为轻量级进程,它和进程一样拥有独立的执行控制,由操作系统负责调度,区别在于线程没有独立的存储空间,而是和所属进程中的其它线程共享一个存储空间,这使得线程间的通信 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号