java获取文件大小时报空指针_java中读取文件 第一行为空 提示空指针异常 怎么解决?...

/**Tochangethislicenseheader,chooseLicenseHeadersinProjectProperties.*Tochangethistemplatefile,chooseTools|Templates*andopenthetemplateintheeditor.*/packagepoidemo1;impor...

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package poidemo1;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

/**

*

* @author Administrator

*/

public class PoiDemo5 {

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

InputStream inputStream=new FileInputStream("f:/设置字体.xls");

POIFSFileSystem fSFileSystem=new POIFSFileSystem(inputStream);

Workbook wb=new HSSFWorkbook(fSFileSystem);

Sheet sheet= wb.getSheetAt(0);//获取一个sheet页

Row row=sheet.getRow(0);//获取第一行

Cell cell=row.getCell(0);//获取单元格

if (cell==null) {

cell=row.createCell(3);

}

cell.setCellType(Cell.CELL_TYPE_STRING);

cell.setCellValue("测试单元格");

FileOutputStream fileOutputStream=new FileOutputStream("f:/设置字体.xls");

wb.write(fileOutputStream);

fileOutputStream.close();

}

}

展开


版权声明:本文为weixin_42110533原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。