导航:首页 > 编程语言 > java文件流写

java文件流写

发布时间:2022-11-05 18:58:11

java 中简述使用流进行读写文本文件的步骤

InputStream
三个基本的读方法
abstract int read() : 读取一个字节数据,并返回读到的数据,如果返回-1,表示读到了输入流的末尾。
int read(byte[] b) : 将数据读入一个字节数组,同时返回实际读取的字节数。如果返回-1,表示读到了输入流的末尾。
int read(byte[] b, int off, int len) :将数据读入一个字节数组,同时返回实际读取的字节数。如果返回-1,表示读到了输入流的末尾。off指定在数组b中存放数据的起始偏移位置;len指定读取的最大字节数。
OutputStream
三个基本的写方法
abstract void write(int b) :往输出流中写入一个字节。
void write(byte[] b) :往输出流中写入数组b中的所有字节。
void write(byte[] b, int off, int len) :往输出流中写入数组b中从偏移量off开始的len个字节的数据。
其它方法
void flush() :刷新输出流,强制缓冲区中的输出字节被写出。
void close() :关闭输出流,释放和这个流相关的系统资源。

Ⅱ mac系统,java编程中文件流的路径是如何写的

看看这个,我昨天刚写的: import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;public class AddList {

private String filePath = "";
private String bakPath = "";
private String content = "";

Scanner sc = new Scanner(System.in);

public String readFile(){
content = "";
if (isNull(filePath)) {
System.out.println("文件存储路径:");
filePath = sc.nextLine();
}
File file = new File(filePath);
FileReader fr = null;
try {
if (file.exists()) {
fr = new FileReader(file);
char[] chars = new char[1024];
int n = 0;
while((n = fr.read(chars)) != -1){
String string = new String(chars, 0, n);
content = content + string;
}
} else {
System.out.println("文件不存在");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return content;
}

public void writeFile(String path){
File file = new File(path);
FileOutputStream fos = null;
mkDirs(path);
try {
fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter pw = new PrintWriter(bos, true);
pw.print(content);
pw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

public void writeFile(){
if (isNull(filePath)) {
System.out.println("文件存储路径:");
filePath = sc.nextLine();
}
File file = new File(filePath);
FileOutputStream fos = null;
mkDirs(filePath);
try {
fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
PrintWriter pw = new PrintWriter(bos, true);
pw.print(content);
pw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

public void mkDirs(String filepath){
if (filepath.indexOf("\\") != -1) {
filepath = filepath.replaceAll("\\", "/");
}
int n = filepath.indexOf("//");
String path = filepath.substring(0, n) + "//";
filepath = filepath.substring(filepath.indexOf("//") + 1, filepath.length());
String[] files = filepath.split("/");
for (int i = 0; i < files.length - 1; i++) {
path = path + files[i];
File file = new File(path);
if (!file.exists()) {
file.mkdir();
}
}
}

public void addImfor(){
System.out.println("--------增加记录---------");
String name = "";
String tel = "";
String email = "";
content = readFile();
while(true){
System.out.println("姓名:");
name = sc.next();
System.out.println("电话:");
tel = sc.next();
System.out.println("Email:");
email = sc.next();
content = content + name + "<>" + tel + "<>" + email +"<==>";
System.out.println("0、Exit 1、继续");
int i = sc.nextInt();
if (i == 0) {
break;
}
}
writeFile();
}

public void deleteImfor(){
System.out.println("---------删除记录---------");
String name = "";
String[] imfors = null;
content = readFile();
while(true){
System.out.println("你要删除的姓名是:");
name = sc.next();
if (content.indexOf(name) != -1) {
imfors = content.split("<==>");
for (int i = 0; i < imfors.length; i++) {
if (imfors[i].indexOf(name) != -1) {
imfors[i] = "";
}
}
content = "";
for (int i = 0; i < imfors.length; i++) {
if (!isNull(imfors[i])) {
content = content + imfors[i] + "<==>";
}
}
writeFile();
System.out.println("删除成功");
} else {
System.out.println("此人不存在");
}
System.out.println("0、Exit 1、继续");
int i = sc.nextInt();
if (i == 0) {
break;
}
}
}

public void viewAll(){
System.out.println("----------显示所有------------");
content = readFile();
if (!isNull(content)) {
String[] imfors = content.split("<==>");
System.out.println("姓名\t电话\tEmail");
for (int i = 0; i < imfors.length; i++) {
String[] imfor = imfors[i].split("<>");
for (int j = 0; j < imfor.length; j++) {
System.out.print(imfor[j] + "\t");
}
System.out.println();
}
} else {
System.out.println("暂时还没有记录");
}
}

public void queryImfor(){
System.out.println("----------查找记录-----------");
content = readFile();
if (!isNull(content)) {
String result = "";
String[] imfors = null;
String[] imfor = null;
String name = "";
boolean bool = false;
while(true){
result = "";
System.out.println("请输入关键字(按姓名查找):");
name = sc.next();
bool = false;
if (content.indexOf(name) != -1) {
imfors = content.split("<==>");
for (int i = 0; i < imfors.length; i++) {
if (imfors[i].indexOf(name) != -1) {
imfor = imfors[i].split("<>");
if (imfor[0].equals(name)) {
bool = true;
result = result + imfors[i] + "<==>";
}
}
}
if (bool) {
imfors = result.split("<==>");
System.out.println("姓名\t电话\tEmail");
for (int i = 0; i < imfors.length; i++) {
imfor = imfors[i].split("<>");
for (int j = 0; j < imfor.length; j++) {
System.out.print(imfor[j] + "\t");
}
System.out.println();
}
} else {
System.out.println("无此人信息");
}
} else {
System.out.println("无此人信息");
}
System.out.println("0、Exit 1、继续");
int i = sc.nextInt();
if (i == 0) {
break;
}
}
} else {
System.out.println("文件还没有记录");
}
}

public void (){
System.out.println("----------备份-----------");
content = readFile();
if (isNull(bakPath)) {
System.out.println("备份全路径:");
bakPath = sc.next();
}
writeFile(bakPath);
System.out.println("备份成功");
}

public boolean isNull(String string){
if (null == string || "" == string || 0 == string.length()) {
return true;
} else {
return false;
}
}

public static void main(String[] args) {
AddList add = new AddList();
Scanner sc = new Scanner(System.in);
int operater = 0;
while(true){
System.out.println("选择功能:\n1、增加记录 2、删除记录 3、显示所有 4、查询记录 5、备份 6、退出");
operater = sc.nextInt();
if (1 == operater) {
add.addImfor();
} else if (2 == operater) {
add.deleteImfor();
} else if (3 == operater) {
add.viewAll();
} else if (4 == operater) {
add.queryImfor();
} else if (5 == operater) {
add.();
} else if (6 == operater) {
System.out.println("谢谢使用");
break;
}
}
}
}

Ⅲ java文件输出流,写到.txt文件,如何实现换行

1 实现的方式总共有3中, 1)原始的 \r\n 方式
2)BufferedWriter的newline()方法
3) System.getProperty()方法
下面使用代码逐一展示 , 写到.txt文件实现换行
2 使用java中的转义符"\r\n":
FileOutputStream fos=new FileOutputStream("c;\\11.txt");
String str="aaa";
str+="\r\n";
fos.write(str);
3 BufferedWriter的newline()方法:
FileOutputStream fos=new FileOutputStream("c;\\11.txt");
BufferedWriter bw=new BufferedWriter(fos);
bw.write("你好");
bw.newline(); //实现换行
4 System.getProperty()方法:
FileOutputStream fos=new FileOutputStream("c;\\11.txt");
String str = "aaa"+System.getProperty("line.separator");
fos.write(str);

Ⅳ java中怎么用io流读写文件

importjava.io.BufferedReader;
importjava.io.BufferedWriter;
importjava.io.FileReader;
importjava.io.FileWriter;
importjava.io.IOException;

publicclassTest14{
publicstaticvoidmain(String[]args)throwsIOException{
StringfPath="C:/test.txt";
//读
BufferedReaderbr=newBufferedReader(newFileReader(fPath));
System.out.println(br.readLine());
br.close();////使用后记得关闭
//写
BufferedWriterbw=newBufferedWriter(newFileWriter(fPath));
bw.write("写一段话到文件里");
bw.flush();
bw.close();//使用后记得关闭
}
}

Ⅳ java 中简述使用流进行读写文本文件的步骤

一、Java IO学习基础之读写文本文件

Java的IO操作都是基于流进行操作的,为了提高读写效率一般需要进行缓冲。

简单的示例程序如下:

/**
* 读出1.txt中的内容,写入2.txt中
*
*/

import java.io.*;

public class ReadWriteFile{
public static void main(String[] args){
try{

File read = new File("c:\\1.txt");
File write = new File("c:\\2.txt");

BufferedReader br = new BufferedReader(
new FileReader(read));
BufferedWriter bw = new BufferedWriter(
new FileWriter(write));
String temp = null;
temp = br.readLine();
while(temp != null){
//写文件
bw.write(temp + "\r\n"); //只适用Windows系统
//继续读文件
temp = br.readLine();
}

bw.close();
br.close();

}catch(FileNotFoundException e){ //文件未找到
System.out.println (e);
}catch(IOException e){
System.out.println (e);
}
}
}

以上是一个比较简单的基础示例。本文上下两部分都是从网上摘抄,合并在一起,方便下自己以后查找。

二、Java IO学习笔记+代码

文件对象的生成和文件的创建

/*
* ProcessFileName.java
*
* Created on 2006年8月22日, 下午3:10
*
* 文件对象的生成和文件的创建
*/
package study.iostudy;
import java.io.*;
public class GenerateFile
{
public static void main(String[] args)
{
File dirObject = new File("d:\\mydir");
File fileObject1 = new File("oneFirst.txt");
File fileObject2 = new File("d:\\mydir", "firstFile.txt");
System.out.println(fileObject2);
try
{
dirObject.mkdir();
}catch(SecurityException e)
{
e.printStackTrace();
}
try
{
fileObject2.createNewFile();
fileObject1.createNewFile();
}catch(IOException e)
{
e.printStackTrace();
}
}
}

文件名的处理
/*
* ProcessFileName.java
*
* Created on 2006年8月22日, 下午3:29
*
* 文件名的处理
*/
package study.iostudy;
import java.io.*;
/*
* 文件名的处理
* String getName(); 获得文件的名称,不包含文件所在的路径。
* String getPath(); 获得文件的路径。
* String getAbsolutePath(); 获得文件的绝对路径。
* String getParent(); 获得文件的上一级目录的名称。
* String renameTo(File newName); 按参数中给定的完整路径更改当前的文件名。
* int compareTo(File pathName); 按照字典顺序比较两个文件对象的路径。
* boolean isAbsolute(); 测试文件对象的路径是不是绝对路径。
*/
public class ProcesserFileName
{
public static void main(String[] args)
{
File fileObject1 = new File("d:\\mydir\\firstFile.txt");
File fileObject2 = new File("d:\\firstFile.txt");
boolean pathAbsolute = fileObject1.isAbsolute();
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * ");
System.out.println("There are some information of fileObject1's file name:");
System.out.println("fileObject1: " + fileObject1);
System.out.println("fileObject2: " + fileObject2);
System.out.println("file name: " + fileObject1.getName());
System.out.println("file path: " + fileObject1.getPath());
System.out.println("file absolute path: " + fileObject1.getAbsolutePath());
System.out.println("file's parent directory: " + fileObject1.getParent());
System.out.println("file's absoulte path: " + pathAbsolute);
int sameName = fileObject1.compareTo(fileObject2);
System.out.println("fileObject1 compare to fileObject2: " + sameName);
fileObject1.renameTo(fileObject2);
System.out.println("file's new name: " + fileObject1.getName());
}
}

测试和设置文件属性
/*
* SetterFileAttribute.java
*
* Created on 2006年8月22日, 下午3:51
*
* 测试和设置文件属性
*/
package study.iostudy;
import java.io.*;
public class SetterFileAttribute
{
/*
* File类中提供的有关文件属性测试方面的方法有以下几种:
* boolean exists(); 测试当前文件对象指示的文件是否存在。
* boolean isFile(); 测试当前文件对象是不是文件。
* boolean isDirectory(); 测试当前文件对象是不是目录。
* boolean canRead(); 测试当前文件对象是否可读。
* boolean canWrite(); 测试当前文件对象是否可写。
* boolean setReadOnly(); 将当前文件对象设置为只读。
* long length(); 获得当前文件对象的长度。
*/
public static void main(String[] args)
{
File dirObject = new File("d:\\mydir");
File fileObject = new File("d:\\mydir\\firstFile.txt");
try
{
dirObject.mkdir();
fileObject.createNewFile();
}catch(IOException e)
{
e.printStackTrace();
}
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * ");
System.out.println("there are some information about property of file object:");
System.out.println("file object : " + fileObject);
System.out.println("file exist? " + fileObject.exists());
System.out.println("Is a file? " + fileObject.isFile());
System.out.println("Is a directory?" + fileObject.isDirectory());
System.out.println("Can read this file? " + fileObject.canRead());
System.out.println("Can write this fie? " + fileObject.canWrite());
long fileLen = fileObject.length();
System.out.println("file length: " +fileLen);
boolean fileRead = fileObject.setReadOnly();
System.out.println(fileRead);
System.out.println("Can read this file? " + fileObject.canRead());
System.out.println("Can write this fie? " + fileObject.canWrite());
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * ");
}
}

文件操作方法
/*
* FileOperation.java
*
* Created on 2006年8月22日, 下午4:25
*
* 文件操作方法
*/

package study.iostudy;
import java.io.*;
/*
* 有关文件操作方面的方法有如下几种:
* boolean createNewFile(); 根据当前的文件对象创建一个新的文件。
* boolean mkdir(); 根据当前的文件对象生成一目录,也就是指定路径下的文件夹
* boolean mkdirs(); 也是根据当前的文件对象生成一个目录,
* 不同的地方在于该方法即使创建目录失败,
* 也会成功参数中指定的所有父目录。
* boolean delete(); 删除当前的文件。
* void deleteOnExit(); 当前Java虚拟机终止时删除当前的文件。
* String list(); 列出当前目录下的文件。
*/
public class FileOperation
* 找出一个目录下所有的文件
package study.iostudy;
import java.io.*;
public class SearchFile
{
public static void main(String[] args)
{
File dirObject = new File("D:\\aa");
Filter1 filterObj1 = new Filter1("HTML");
Filter2 filterObj2 = new Filter2("Applet");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("list HTML files in directory: " + dirObject);
String[] filesObj1 = dirObject.list(filterObj1);
for (int i = 0; i < filesObj1.length; i++)
{
File fileObject = new File(dirObject, filesObj1[i]);
System.out.println(((fileObject.isFile())
? "HTML file: " : "sub directory: ") + fileObject);
}
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
String[] filesObj2 = dirObject.list(filterObj2);
for (int i = 0; i < filesObj2.length; i++)
{
File fileObject = new File(dirObject, filesObj2[i]);
System.out.println(((fileObject.isFile())
? "htm file: " : "sub directory: ") + fileObject);
}
}
}

class Filter1 implements FilenameFilter
{
String fileExtent;
Filter1(String extentObj)
{
fileExtent = extentObj;
}

public boolean accept(File dir, String name)
{
return name.endsWith("." + fileExtent);
}
}

class Filter2 implements FilenameFilter
{
String fileName;
Filter2(String fileName)
{
this.fileName = fileName;
字符流处理
* ProcesserCharacterStream.java
* 字符流处理
*
* java.io包中加入了专门用于字符流处理的类,这些类都是Reader和Writer类的子类,
* Reader和Writer是两个抽象类,只提供了一系列用于字符流处理的接口,不能生成这
* 两个类的实例。
* java.io包中用于字符流处理的最基本的类是InputStreamReader和OutputStreamWriter,
* 用来在字节流和字符流之间作为中介。
*
* 下面是InputStreamReader类和OutputStreamWriter类的常用方法:
*
* public InputStreamReader(InputStream in)
* 根据当前平台缺省的编码规范,基于字节流in生成一个输入字符流。
* public InputStreamReader(InputStream in, String sysCode)throws UnSupportedEncodingException
* 按照参数sysCode指定的编码规范,基于字节流in构造输入字符流,如果不支持参数sysCode中指定的编码规范,就会产生异常。
* public OutputStreamWriter(OutputStream out)
* 根据当前平台缺省的编码规范,基于字节流out生成一个输入字符流。
* public OutputStreamWriter(OutputStream out, String sysCode) throws UnsupportedEncodingException
* 按照参数sysCode指定的编码规范,基于字节流out构造输入字符流,如果不支持参数sysCode中指定的编码规范,就会产生异常。
* public String getEncoding()
* 获得当前字符流使用的编码方式。
* public void close() throws IOException
* 用于关闭流。
* public int read() throws IOException
* 用于读取一个字符。
* public int read(char[] cbuf, int off, int len)
* 用于读取len个字符到数组cbuf的索引off处。
* public void write(char[] cbuf, int off, int len) throws IOException
* 将字符数组cbuf中从索引off处开始的len个字符写入输出流。
* public void write(int c) throws IOException
* 将单个字符写入输入流。
* public void write(String str, int off, int len) throws IOException
* 将字符串str中从索引off位置开始的ltn个字符写入输出流。
*
* 此外,为了提高字符流处理的效率,在Java语言中,引入了BufferedReader和BufferWriter类,这两个类对字符流进行块处理。
* 两个类的常用方法如下:
* public BufferedReader(Reader in)
* 用于基于普通字符输入流in生成相应的缓冲流。
* public BufferedReader(Reader in, int bufSize)
* 用于基于普通字符输入流in生成相应的缓冲流,缓冲区大小为参数bufSize指定。
* public BufferedWriter(Writer out)
* 用于基于普通字符输入流out生成相应的缓冲流。
* public BufferedWriter(Writer out, int bufSize)
* 用于基于普通字符输入流out生在相应缓冲流,缓冲流大小为参数bufSize指定。
* public String readLine() throws IOException
* 用于从输入流中读取一行字符。
* public void newLine() throws IOException
* 用于向字符输入流中写入一行结束标记,值得注意的是,该标记不是简单的换行符"\n",而是系统定义的属性line.separator。
在上面的程序中,我们首先声明了FileInputStream类对象inStream和
* FileOutputStream类的对象outStream,接着声明了BufferInputStream
* 类对象bufObj、BufferedOutputStream类对象bufOutObj、
* DataInputStream类对象dataInObj以及PushbackInputStream类对象pushObj,
* 在try代码块中对上面这些对象进行初始化,程序的目的是通过BufferedInputStream
* 类对象bufInObj和BufferedOutputStream类对象bufOutObj将secondFile.txt
* 文件中内容输出到屏幕,并将该文件的内容写入thirdFile.txt文件中,值得注意的是,
* 将secondFile.txt文件中的内容输出之前,程序中使用
* "System.out.println(dataInObj.readBoolean());" 语句根据readBoolean()结果
* 输出了true,而secondFile.txt文件开始内容为“Modify”,和一个字符为M,
* 因此输出的文件内容没有“M”字符,thirdFile.txt文件中也比secondFile.txt
* 文件少第一个字符“M”。随后,通过PushbackInputStream类对象pushObj读取
* thirdFile.txt文件中的内容,输出读到的字符,当读到的不是字符,输出回车,将字符
* 数组pushByte写回到thirdFile.txt文件中,也就是“ok”写回文件中。
* 对象串行化
* 对象通过写出描述自己状态的数值来记录自己,这个过程叫做对象串行化。对象的寿命通
* 常是随着生成该对象的程序的终止而终止,在有些情况下,需要将对象的状态保存下来,然后
* 在必要的时候将对象恢复,值得注意的是,如果变量是另一个对象的引用,则引用的对象也要
* 串行化,串行化是一个递归的过程,可能会涉及到一个复杂树结构的串行化,比如包括原有对
* 象,对象的对象等。
* 在java.io包中,接口Serializable是实现对象串行化的工具,只有实现了Serializable
* 的对象才可以被串行化。Serializable接口中没有任何的方法,当一个类声明实现Seriali-
* zable接口时,只是表明该类遵循串行化协议,而不需要实现任何特殊的方法。
* 在进行对象串行化时,需要注意将串行化的对象和输入、输出流联系起来,首先通过对
* 象输出流将对象状态保存下来,然后通过对象输入流将对象状态恢复。

Ⅵ Java流的文件写入问题!

使用 java.util.Sanner sc=new java.util.Sanner(System.in);
sc.nextLine();//输入一行字符串,Enter结束

//该方法仅能读取UTF格式的字符,而键盘的不能输入UTF-8格式字符,就是你按Enter键时,按照UTF-8的格式,它并不是Enter

UTF-8 修改版

DataInput 和 DataOutput 接口的实现表示稍作改版的 UTF-8 格式的 Unicode 字符串。(关于标准 UTF-8 格式的信息,请参阅 The Unicode Standard, Version 4.0 的 3.9 Unicode Encoding Forms 节)。注意,在下表中,最高有效位显示在最左边的列中。
这种格式与标准 UTF-8 格式之间的不同如下:

* null 字节 '\u0000' 是用 2-byte 格式而不是 1-byte 格式编码的,因此已编码的字符串中决不会有嵌入的 null。
* 仅使用 1-byte、2-byte 和 3-byte 格式。
* 增补字符是以代理项对的形式表示的。

Ⅶ java中关于文件流的读写(Writer Reader)

你好 我刚刚做了个例子 方便你看
class_writer class 这个例子是从 一个文件中读取数据然后插入了数据库中 你可以只看读取与插入的过程 希望能帮到你.
public class writer {
public boolean writ(String str) {
boolean success=false;
str = str.replaceAll(" ", "").replaceAll("\"", "");
String[] strs = str.split(",");
BaseJDBC base = new BaseJDBC();
String ML = "";
Statement stmt;
Connection conn;
ML = "'"+strs[0].replace(" ", "").trim() + "','"
+ strs[1].replace(" ", "").trim() + "','"
+ strs[2].replace(" ", "").trim() + "','"
+ strs[3].replace(" ", "").trim() + "','"
+ strs[4].replace(" ", "").trim()+ "','"
+ strs[5].replace(" ", "").trim()+"','"
+ strs[6].replace(" ", "").trim()+"'";
String query = "INSERT INTO BANK_INFO VALUES(" + ML + ")";
if (!strs[0].equals("参与者行号")) {
try {
conn=base.genConn();
stmt = conn.createStatement();
int num=stmt.executeUpdate(query);
if(num==1)success=true;
stmt.close();
conn.close();
System.out.println();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getMessage());
}
}
return success;
}

//class readingclass
public class reading {
public static void readFileByLines(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
while ((tempString = reader.readLine()) != null) {
writer w=new writer();
try {
tempString.getBytes("utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(!w.writ(tempString)){
System.out.println("第"+line+"行出现异常:"+tempString);
}else{
System.out.println("第"+line+"行初始化成功!");
}
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
//1927
public static void main(String[] args) {
// TODO Auto-generated method stub
String fileName = "D:\\BankInfo_20110714094211.csv";
readFileByLines(fileName);

}

Ⅷ java写入文件流

简单的方法就是先把这个HTML全部读成一个STRING,然后正则匹配<P>标签 然后substring截断 插入你要插入的一串字。。。。
或者用HTMLParser也可以
http://allenj2ee.javaeye.com/blog/222454俺就是从这学的

Ⅸ Java读写文件的几种方法

java读取配置文件的几种方法如下:
方式一:采用ServletContext读取,读取配置文件的realpath,然后通过文件流读取出来。因为是用ServletContext读取文件路径,所以配置文件可以放入在web-info的classes目录中,也可以在应用层级及web-info的目录中。文件存放位置具体在eclipse工程中的表现是:可以放在src下面,也可放在web-info及webroot下面等。因为是读取出路径后,用文件流进行读取的,所以可以读取任意的配置文件包括xml和properties。缺点:不能在servlet外面应用读取配置信息。
方式二:采用ResourceBundle类读取配置信息,
优点是:可以以完全限定类名的方式加载资源后,直接的读取出来,且可以在非Web应用中读取资源文件。缺点:只能加载类classes下面的资源文件且只能读取.properties文件。

Ⅹ java文件流怎么写

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

private File fileObject;
private String savePath;
FileOutputStream fileOutputStream = new FileOutputStream("savePath");
FileInputStream fileInputStream = new FileInputStream(fileObject);
byte[] buffer = new byte[100];
int len = 0;
while ((len = fileInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, len);
}

阅读全文

与java文件流写相关的资料

热点内容
五菱宏光空调压缩机 浏览:64
为什么app占用几百兆 浏览:676
自动解压失败叫我联系客服 浏览:482
易语言新手源码 浏览:456
oa服务器必须有固定ip地址 浏览:42
传奇源码分析是什么 浏览:267
解放压缩机支架 浏览:255
程序员秃顶搞笑相遇 浏览:6
IBM手机app商店叫什么名字 浏览:834
jpeg压缩质量 浏览:774
云服务器评测对比 浏览:145
java日期转string 浏览:221
openfire源码编译 浏览:897
在线小工具箱引流网站源码 浏览:337
非科班程序员自学 浏览:801
压缩泡沫鞋底底材 浏览:220
程序员职场第一课2正确的沟通 浏览:680
遇到不合法app应该怎么办 浏览:92
汇编程序编译后的文件 浏览:81
大智慧均线源码 浏览:374