运用JAVA读取txt文件
2010-06-22 13:46
309 查看
package com.b;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* @author dengshaohua
*/
public class Utils {
/**
* 读取数据
*/
public String ReadDate() {
String url = "c:/data.txt";
String strs = "";
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);
}
System.out.print(sb.toString());
String a = sb.toString().replaceAll("@@@@@", ",");
strs = a.substring(0,a.length()-1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return strs ;
}
public static void main(String a[])
{
Utils util = new Utils();
String cc = util.ReadDate();
System.out.println("result...."+cc);
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* @author dengshaohua
*/
public class Utils {
/**
* 读取数据
*/
public String ReadDate() {
String url = "c:/data.txt";
String strs = "";
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);
}
System.out.print(sb.toString());
String a = sb.toString().replaceAll("@@@@@", ",");
strs = a.substring(0,a.length()-1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return strs ;
}
public static void main(String a[])
{
Utils util = new Utils();
String cc = util.ReadDate();
System.out.println("result...."+cc);
}
}
相关文章推荐
- 运用JAVA读取txt文件
- 运用JAVA读取txt文件(BufferReader)
- Java读取txt文件和写入txt文件
- java 实现以行为单位读取txt文件(1)
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法
- Java读取txt文件中的数据赋给String变量方法
- JAVA读取txt文件
- java学习笔记 读取pdf文件并写成txt文件输出
- java实现读取TXT文件的方法
- Java读取txt文件 copy文件 写入文件
- java 文件操作 读取txt文本(兄弟常开心)
- java读取txt文件内容
- Java读取txt文件的方法
- java读取txt文件内容
- JAVA 创建TXT文件,写入文件内容,读取文件内容
- Java读取TXT文本文件乱码解决方案
- Java方式读取本地服务器上的txt文件
- 怎样用JAVA打开一个已经写好的TXT文件? 是打开,不是读取啊!!!
- java读取txt文件
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例