Java简单文件处理
来源:互联网 发布:淘宝粤通卡车宝是什么 编辑:程序博客网 时间:2024/06/08 17:51
/** * Created by z5139 on 2016/5/17 0017. */public class IOtxt { /** * 读取数据 */ public static String ReadData(String url) { String buffer = null; 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); } buffer = sb.toString(); read.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buffer; } /** * 写入数据 */ public static boolean WriteData(String url, int content) { BufferedWriter out = null; boolean flag; try { File file = new File(url); if (!file.exists()) { file.createNewFile(); } out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(file, true))); out.write(String.valueOf(content) + " "); flag = true; return flag; } catch (Exception ex) { System.out.println(ex); flag = false; return flag; } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * 创建文件 */ public static boolean createFile(String url) throws Exception { boolean flag = false; File fileName = new File(url); try { if (!fileName.exists()) { fileName.createNewFile(); flag = true; } } catch (Exception e) { flag = false; Log.e("tag", "创建失败"); } return flag; } /** * String转 int 数组 */ public static int[] StringToInt(String a) { String str[] = a.trim().split("\\s"); int recordInt[] = new int[str.length]; for (int i = 0; i < str.length; i++) { recordInt[i] = Integer.parseInt(str[i]); } return recordInt; } /** * 列出指定文件夹内路径 */ public static String[] listFile(String path) { File file = new File(path); File[] tempList = file.listFiles(); String filepath[] = new String[tempList.length]; System.out.println("该目录下对象个数:" + tempList.length); for (int i = 0; i < tempList.length; i++) { if (tempList[i].isFile()) { filepath[i] = tempList[i].getName(); } } return filepath; } /** * 列出指定文件夹内时间 */ public static String[] listTime(String path) { File file = new File(path); File[] tempList = file.listFiles(); String time[] = new String[tempList.length]; System.out.println("该目录下对象个数:" + tempList.length); for (int i = 0; i < tempList.length; i++) { if (tempList[i].isFile()) { time[i] = tempList[i].getName().substring(0, 20); } } return time; } /** * 列出指定文件夹内HR */ public static String[] listHR(String path) { File file = new File(path); File[] tempList = file.listFiles(); String HR[] = new String[tempList.length]; System.out.println("该目录下对象个数:" + tempList.length); for (int i = 0; i < tempList.length; i++) { if (tempList[i].isFile()) { HR[i] = tempList[i].getName().substring(20,22); } } return HR; } //删除空白文件 public static void deleteEmpty(String path){ File file = new File(path); if (file.length() == 0){ file.delete(); } } //创建文件夹 public static void makeRootDirectory(String filePath) { File file; try { file = new File(filePath); if (!file.exists()) { file.mkdirs(); } } catch (Exception e) { Log.i("error:", e + ""); } }}
0 0
- Java简单文件处理
- Java 简单IO文件处理
- Java 文件处理简单工具函数
- JAVA处理Excel文件---生成简单的Excel文件
- JAVA处理Excel文件---生成简单的Excel文件
- PHP 简单文件处理
- 文件上传 简单处理
- 文件的简单处理
- Python 简单文件处理
- 简单的文件处理
- 简单的文件处理
- java读取文件数据进行一些简单处理的例子
- java读取文件数据进行一些简单处理的例子
- 简单的文件处理类
- C&&C++ 简单 文件处理
- 简单文件数据读入处理
- sed进行文件简单处理
- Python文件数据简单处理
- 金蝶K3-WISE V13.1加密狗驱动-50用户补丁
- Javascript学习笔记part1(Table单元格相同数据自动合并)补充
- redis
- OC中的selector选择子
- POI操纵EXCEL文档之导入文档(一)
- Java简单文件处理
- Android Service最全面的解析
- Hibernate中的Entity类中的getter/setter方法
- AP IExpense 杂记随笔
- Hadoop机器运行一段时间后hadoop不能stop-all.sh的问题
- poj 2502最短路subway
- 打包文档
- Hexo搭建独立博客,托管到Github和Coding
- 点击图片变大