易截截图软件、单文件、免安装、纯绿色、仅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);
}

}
}


相关文档:

sql 2005 存储过程分页 java 代码

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列 ......

Effective java 代码优化实例

package chape7;
/**
* 檢查參數的有效性
*    當編寫方法或者構造器時,應該考慮他的參數有什麽限制 應該吧這些限制寫在文檔中,並且在這個方法的開頭 ......

java exception java异常汇总(3)

java exception 解决方案 - 我的异常网|异常|exception   791 - java.lang.NoSuchMethodError 792 - RuntimeException 793 - org.hibernate.exception.SQLGrammarException 794 - Internal Error 795 - 自定义异常 796 - org.dom4j.DocumentException 797 - java.net.SocketException 798 - Exception对象 799 - SQLE ......

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号