java 判断网络类型_javaexcel判断类型

1. java如何判断数据类型

给你一个封装好的方法,只要把excel中的cell放入就会返回对应的值,里面有类型检测

public static String getExcelCellValue(HSSFCell cell) {

String ret = "";

// if (HSSFDateUtil.isCellDateFormatted(cell)) {

// Date date = cell.getDateCellValue();

// ret = "" + date.getTime();

// } else

try {

if (cell == null) {

ret = "";

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

ret = cell.getStringCellValue().trim();

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {

ret = "" + cell.getNumericCellValue();

String temp = ret.substring(ret.indexOf(".") + 1, ret.length());

try {

if (Integer.parseInt(temp) == 0) {

ret = ret.substring(0, ret.indexOf("."));

}

} catch (Exception ex) {

}

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {

ret = cell.getCellFormula();

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {

ret = "" + cell.getErrorCellValue();

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {

ret = "" + cell.getBooleanCellValue();

} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {

ret = "";

}

} catch (Exception ex) {

ex.printStackTrace();

ret = "";

}

return ret;

}

2. java 判断文件类型

package com.test;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Ch2 {

private static final String RAGEX="[0x00-0x07]";

public static void main(String[] args) throws IOException {

File file=new File("c:/abc");

File[] files=file.listFiles();

for(int i=0;i<files.length;i++){

System.out.println(files[i].getName()+"\t"+getCheck(files[i]));

}

}

public static boolean getCheck(File f) throws IOException{

BufferedReader br=new BufferedReader(new FileReader(f));

String temp="";

while((temp=br.readLine())!=null){

for(int i=0;i<temp.length();i++){

if((temp.charAt(i)+"").matches(RAGEX)){

return true;

}

}

}

br.close();

return false;

}

}

//c:/abc是文件目录.里面可以随意放几个文件.但不要有文件夹.没做验证.

//根据楼上所说解答.分给楼上就行了,谢谢楼上!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值