博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件读写&文件夹遍历
阅读量:4213 次
发布时间:2019-05-26

本文共 1080 字,大约阅读时间需要 3 分钟。



文件读写

 

读文件()

private void readFile(File file) throws IOException {		FileInputStream stream = null;		stream = new FileInputStream(file);		DataInputStream sysin = new DataInputStream(stream);		String line = null;		while ((line = sysin.readLine()) != null) {			if (line.trim().equals("")) {				continue;			}			System.out.println(line);		}	}

写文件

public void write(String filePath) throws IOException {		File file = new File(filePath);		if (!file.exists())			file.createNewFile();		FileOutputStream out = new FileOutputStream(file, false);		String data = "aa\nbb";		out.write(data.toString().getBytes("utf-8"));		ParsePclntResult obj = new ParsePclntResult();	}

递归删除指定文件夹下的文件(遍历文件)

private void cleanupRecursive(File file) {		try {			if (file.isDirectory()) {				for (File child : file.listFiles()) {					cleanupRecursive(child);				}				if (file.listFiles().length == 0) {					file.delete();				}			} else {				if (file.getName().endsWith(".xls")) {					file.delete();				}			}		} catch (Exception e) {			System.out.println(e.getMessage() + "\nFile:" + file.getAbsolutePath());		}	}

转载地址:http://fcumi.baihongyu.com/

你可能感兴趣的文章
C/C++文件操作[转载]
查看>>
专业计划
查看>>
小米笔试:最大子数组乘积
查看>>
常见的排序算法
查看>>
5.PyTorch实现逻辑回归(二分类)
查看>>
6.PyTorch实现逻辑回归(多分类)
查看>>
8.Pytorch实现5层全连接结构的MNIST(手写数字识别)
查看>>
9.PyTorch实现MNIST(手写数字识别)(2卷积1全连接)
查看>>
hdu 3460 Ancient Printer(trie tree)
查看>>
中间数
查看>>
KMP求前缀函数(next数组)
查看>>
KMP
查看>>
poj 3863Business Center
查看>>
Android编译系统简要介绍和学习计划
查看>>
Android编译系统环境初始化过程分析
查看>>
user2eng 笔记
查看>>
DRM in Android
查看>>
ARC MRC 变换
查看>>
Swift cell的自适应高度
查看>>
【linux】.fuse_hiddenXXXX 文件是如何生成的?
查看>>