java 将数据写进文件

/*每次只写入一行数据 只需要调用特定的方法即可。*/

package com.second.File;

import java.io.*;

/** * Created by hasee on 2016/11/15. */public class WriteFile {    private BufferedWriter bw = null;

public int openWrite(String address, String strCodeFormat) {        if (strCodeFormat == null || address == null || address.length() == 0 || strCodeFormat.length() == 0) {            //错误代码 101 输入的信息为空            return 101;        }        try {            bw = new BufferedWriter(                    new OutputStreamWriter(                            new FileOutputStream(address), strCodeFormat));            return 1;        } catch (FileNotFoundException e) {            e.printStackTrace();            return 204;        } catch (UnsupportedEncodingException e) {            e.printStackTrace();            return 201;        }    }

public int save(String strLine) {        if (bw == null) {            return 301;        }        try {            bw.write(strLine);            return 1;        } catch (IOException e) {            e.printStackTrace();        }        return 0;    }

public int closeWrite() {        if (bw == null) {            return 301;        }        try {            bw.close();            return 1;        } catch (IOException e) {            e.printStackTrace();            return 301;        }    }}
时间: 2024-08-07 17:15:31

java 将数据写进文件的相关文章

JAVA读、写EXCEL文件

采用jxl.jar包,网上下载,百度一下到出都是.希望可以帮助到大家. 接下来直接贴代码: <span style="font-size:18px;">public List getValue(String fileName){ String str=ExcelOparations.readExcel(fileName).trim(); String[] str4n= str.split("\n"); List list1 = new ArrayList

java:IO-读写大文件

import java.io.*; class Test { public static void main(String args[]){ FileInputStream fin =null; FileOutputStream fout = null; try{ fin = new FileInputStream("e://d/from.txt"); fout = new FileOutputStream("e://d/to.txt"); byte [] arr

java 写入数据到Excel文件中_Demo

=======第一版:基本功能实现======= import com.google.common.collect.Maps; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io

java使用POI写Excel文件

参考地址:http://www.cnblogs.com/xwdreamer/archive/2011/07/20/2296975.html 1 jar包 网上下载 2 源代码 package zjr.amy.excel; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java

c#逐行分元素读取记事本txt数据写进数据库

其实这里最关键的一个方法是 StreamReader类里的 ReadLine();这个方法可以逐行读取txt流里面的数据.写了个简单的demo,已经加上了详细的注释说明. ok,好了,不废话,下面直接上代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 public void InputData()          {              Dat

java将数据生成csv文件

1,httpRequest接口触发进程[或者可以换成其他方式触发] /** * 出入库生成CSV文件 * @param req * @param params * @return */@RequestMapping(value = "explanCsvFileToOrder")ResponseMessage explanCsvFileToOrder(HttpServletRequest req, @RequestParam Map<String, String> param

.NET 泛型集合数据写CSV文件

1.功能类 using System;using System.Collections.Generic;using System.ComponentModel;using System.IO;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks; namespace Infrastructure{    public static class FileExtensions 

java把数据到指定文件

String filename = "F:\\test123.txt";FileOutputStream stream = null;OutputStreamWriter writer = null;try { stream = new FileOutputStream(filename, true); writer = new OutputStreamWriter(stream); writer.write("test"); writer.write("

Hadoop HDFS (3) JAVA访问HDFS之二 文件分布式读写策略

先把上节未完成的部分补全,再剖析一下HDFS读写文件的内部原理 列举文件 FileSystem(org.apache.hadoop.fs.FileSystem)的listStatus()方法可以列出一个目录下的内容. public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException; public FileStatus[] listStatus(Path[] files) throws FileNot