mapping file(为什么File mapping比普通文件读写效率高)

本文目录
- 为什么File mapping比普通文件读写效率高
- jxl2.6.10.jar可以读取csv吗
- eclipse里的maven 里change mapping file location这个用修改吗
- 文件映射后是操作mapping句柄还是file句柄
- No persister for nhibernate 解决下面的问题
为什么File mapping比普通文件读写效率高
java提供了搞笑读取文件的方式:文件流,下面以FileInputStream和Apache Commons IO流两种读取方式来详细讲解: 以下两种代码均是读取一个大约1G的文件: 1、文件流 FileInputStream inputStream = null; Scanner sc = null; try { inputStream ...
jxl2.6.10.jar可以读取csv吗
可以读出的,方法如下
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import com.csvreader.CsvReader;
import EmgDzdpMapping;
public class ReaderMappingFile {
/**
* 读csv格式.
* 开源jar包有opencsv, javacsv, csvObjects(可以装换成对象),csv, csvjdbc等. 此处用javacsv
* @param dir
* @return
*/
public static List《EmgDzdpMapping》 readCsvFile(String dir) {
List《EmgDzdpMapping》 list = new ArrayList《EmgDzdpMapping》();
List《File》 files = getFile(dir);
CsvReader reader = null;
ArrayList《String》(); //用来保存数据
try {
for (File file : files) {
if (!file.getName().contains("csv"))
continue;
reader = new CsvReader(file.getAbsolutePath(),’,’,Charset.forName("SJIS"));
//一般用这编码读就可以了
reader.readHeaders(); // 跳过表头 如果需要表头的话,不要写这句。
while(reader.readRecord()){ //逐行读入除表头的数据
csvList.add(reader.getValues());
}
reader.close();
for(int row=0;row《csvList.size();row++){
for(int colum = 0; colum《csvList.get(row).length; colum++){
System.out.println(csvList.get(row));//取得第row行第colum列的数据
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
} finally {
if(reader != null) {
reader.close();
}
}
return null;
}
/**
* 不使用递归,遍历文件夹.速度没有递归效果快
*/
private static List《File》 getFile(String rootDir) {
List《File》 files = new ArrayList《File》();
LinkedList《File》 list = new LinkedList《File》();
File dir = new File(rootDir);
File file = dir.listFiles();
for (int i = 0; i 《 file.length; i++) {
if (file.isDirectory()) {
list.add(file);
} else {
// System.out.println(file.getAbsolutePath());
files.add(file);
}
}
File tmp;
while (!list.isEmpty()) {
tmp = list.removeFirst();// 循环操作,删除元素。
if (tmp.isDirectory()) {
file = tmp.listFiles();
if (file == null)
continue;
for (int i = 0; i 《 file.length; i++) {
if (file.isDirectory()) {
list.add(file);
} else {
// System.out.println(file.getAbsolutePath());
files.add(file);
}
}
} else {
// System.out.println(tmp.getAbsolutePath());
files.add(tmp);
}
}
return files;
}
/**
* jxl读excel格式.
* poi, jxl, jxls等。
* jxl是一个韩国人写的java操作excel的工具, 在开源世界中,有两套比较有影响的API可供使用,一个是POI,一个是jExcelAPI。其中功能相对POI比较弱一点。但jExcelAPI对中文支持非常好,API是纯Java的, 并不依赖Windows系统,即使运行在Linux下,它同样能够正确的处理Excel文件。 另外需要说明的是,这套API对图形和图表的支持很有限,而且仅仅识别PNG格式
* @param dir
* @return
*/
public static List《EmgDzdpMapping》 readExcelFile(String dir) {
Workbook book = null;
List《File》 files = getFile(dir);
try {
for (File file : files) {
if (!file.getName().contains("xls"))
continue;
book = Workbook.getWorkbook(file);
// 获得第一个工作表对象,暂时只处理一个sheet.
Sheet sheet = book.getSheet(0);
int columnum = sheet.getColumns(); // 得到列数
int rownum = sheet.getRows(); // 得到行数
System.out.println(columnum);
System.out.println(rownum);
for (int i = 0; i 《 rownum; i++) // 循环进行读写
{
for (int j = 0; j 《 columnum; j++) {
Cell cell1 = sheet.getCell(j, i);
String result = cell1.getContents();
System.out.print(result);
System.out.print(" \t ");
}
System.out.println();
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (book != null) {
book.close();
}
}
return null;
}
public static void main(String args) {
readCsvFile("F:\\11_maintenance\\问题《a href="file://\\20120104_02\\test"》\\20120104_02\\test《/a》");
//readExcelFile("F:\\11_maintenance\\问题\\20120104_02\\test");
// System.out.println(getFile("F:\\11_maintenance\\问题\\20120104_02\\dfyl111230").size());;
}
}
public class EmgDzdpMapping {
public String richpoisrc;
public Stringrichpoiid;
public String emgpoiid;
public String emgversion;
public String update;
/**A:代表add新增*/
public String deltatyp;
public EmgDzdpMapping(String richpoisrc, String richpoiid, String emgpoiid,
String emgversion, String update, String deltatyp) {
super();
this.richpoisrc = richpoisrc;
this.richpoiid = richpoiid;
this.emgpoiid = emgpoiid;
this.emgversion = emgversion;
this.update = update;
this.deltatyp = deltatyp;
}
public String getRichpoisrc() {
return richpoisrc;
}
public void setRichpoisrc(String richpoisrc) {
this.richpoisrc = richpoisrc;
}
public String getRichpoiid() {
return richpoiid;
}
public void setRichpoiid(String richpoiid) {
this.richpoiid = richpoiid;
}
public String getEmgpoiid() {
return emgpoiid;
}
public void setEmgpoiid(String emgpoiid) {
this.emgpoiid = emgpoiid;
}
public String getEmgversion() {
return emgversion;
}
public void setEmgversion(String emgversion) {
this.emgversion = emgversion;
}
public String getUpdate() {
return update;
}
public void setUpdate(String update) {
this.update = update;
}
public String getDeltatyp() {
return deltatyp;
}
public void setDeltatyp(String deltatyp) {
this.deltatyp = deltatyp;
}
}
eclipse里的maven 里change mapping file location这个用修改吗
1.首先到EclipseMarketplace中下载MavenIntegrationforEclipseWTP,如下,之后查看是否成功下载,Window-》ShowView-》Maven2.下载Maven的bin下载下来之后,解压,找个路径放进去,把bin的位置,设在环境变量里新建环境变量MAVEN_HOMEPATH里加入bin的路径完成之后,检测一下(必须先配好JAVA的环境变量)进入cmdecho%MAVEN_HOME%mvn-v之后便会出现版本信息,就算是路径配置成功了3.为了使得Eclipse中安装的Maven插件,同windows中安装的那个相同,需要让eclipse中的maven重新定位一下Window-》Preference-》Maven-》Installation-》Add如下,4.新建一个Maven工程之后选择,UseDefaultWorkspaceLocation(其实这个路径是documentsandsettings\用户名\.m2\repository)之后点击Next,进入GroupId和ArtifactId的填写,之后Maven项目建立,5.打开pom.xml试着添加MySQL的JDBC驱动添加如下配置,viewplaincopycom.google.code.gsongson2.2.2
文件映射后是操作mapping句柄还是file句柄
如果你在创建文件的时候指定的句柄是通过OpenFile或者CreateFile得到的句柄且打开或者创建文件的时候有GENERIC_WRITE属性的,那么对映射的操作是会写入文件的。
句柄可以用CloseHandle来关闭,MapViewOfFile的关闭函数是UnmapViewOfFile。DuplicateHandle可以用来复制句柄。如果对文件操作,那么最后也得关闭文件句柄。
No persister for nhibernate 解决下面的问题
出现No persister for错误后有如下三种解决办法:
1.检查hbm.xml文件,配置文件后缀名写错 mapping file 必须是.hbm.xml结尾。
2.hibernate 的mapping 配置文件是xml,属性必须设置成“嵌入的资源”
3.检查cfg.xml文件,看看类的hbm.xml文件名是不是已经写上了。
3.对于one-to-many(Parent-to-Child)的关系,应该是
child.setParent(parent),而不是child.setParent(parent.id)

更多文章:
sql语句优化面试(面试问到 数据库性能优化 怎么回答 我是Oracle数据库)
2025年7月30日 02:15
图片转换代码软件(求一款图片转网页代码的工具,就是可以把图片转换成网页广告的那种,)
2025年6月30日 23:30
desense(手机desense测试,中文是什么意思怎么测试)
2025年11月12日 03:00
如何使用ubuntu系统(win10安装ubuntu双系统怎么装)
2025年9月4日 20:00
sql数据库多少钱(access sql 等的数据库,开发工具多少钱运行平台多少钱)
2026年1月21日 20:15
php环境搭建的原理(什么是PHPWEB环境的搭建及其作用)
2026年8月23日 16:15
c语言一维数组有几个数(c语言的一维数组中至少要有几个元素)
2025年11月27日 13:30
1111101100101110转为16进制?将23456表为16进制数
2025年12月19日 18:30
指针变量为什么占4个地址(C语言中,为什么指针变量无论指向那个类型的变量,其所占的字节都为4个字节详解)
2025年7月27日 19:00
html5模板 支付成功(html5怎么实现支付宝实时转账)
2025年7月5日 15:45
js jquery面试(jquery中怎么调用js方法调用)
2025年8月8日 03:45










