高手讨论题:java读文件的能力真的很差吗? 我刚才在csdn里粘贴的,愿赐教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 : bluerain2002(蓝雨灰天) :( 我也有相同的问题,老解决不了。efly(易飞) 你是水货,不懂就别搀和关注 唉,,,以上代码windows下绝对没问题,就世unix下出错 看你想读什么,文本的,二进制的?怎么读?随机的?顺序的?关键看你想解决什么问题。这个是最重要的。YOU 二位 SEE?只有知道了做什么,才能找到BEST SOLUTION。 真心求解。以上方法一种顺序,一种随机啊。二进制的没多大问题,主要是较大一点的文本文件,居然莫名其妙的掉个把字符,也是在windows下没问题,unix下出问题。 这个问题我好象也遇到过,不是JAVA的问题.是UNIX下的文本文件跟WINDOWS下的文本文件的结构好象不太一样.好象UNIX下的文本文件每一行的换行符是\r而WINDOS下是\r\n.记不太清了,看看有没有帮助吧. abstract class GeneralFace implements WHtmTag { abstract String getDocument(String tempFile, String[] replacements); public void getDocument( String tempFile, String docFile, String[] replacements) { setFileContent(docFile, getDocument(tempFile, replacements)); } protected String getFileContent(String filePath) { String str_ret = ""; String line = null; //Read file try { FileReader fr = new FileReader(filePath); BufferedReader br = new BufferedReader(fr); while ((line = br.readLine()) != null) { str_ret += line + "\r\n"; } br.close(); fr.close(); } catch (FileNotFoundException fnfe) { System.out.println("File_not_found"); } catch (IOException ioe) { System.out.println("IO_reading_error"); } return str_ret; } protected void setFileContent(String filePath, String content) { try { FileWriter fw = new FileWriter(filePath); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.flush(); bw.close(); fw.close(); } catch (IOException ioe) { System.out.println("IO_writing_error"); } }}读文本你试试,看有多长的文本它读不出来?这个是在linux环境下写的。window 下照样通过。 请教一下类的设计的一个问题 高手请进!!! 我写了这样一个监听 新手关于String的一个小问题 树结点数据实体不同,如何建造树. 简单问题望解决 getCanonicalPath()和getAbsolutePath的区别是什么? Aspectj真正的用处在哪? 高分求助 有关汉字的一个问题! 请教!为什么在别的机上运行不能显示中文 java.io.Serializable 的用处?????
:( 我也有相同的问题,老解决不了。
efly(易飞) 你是水货,不懂就别搀和
关注
只有知道了做什么,才能找到BEST SOLUTION。
较大一点的文本文件,居然莫名其妙的掉个把字符,也是在windows下没问题,unix下出问题。
而WINDOS下是\r\n.记不太清了,看看有没有帮助吧.
String tempFile,
String docFile,
String[] replacements) {
setFileContent(docFile, getDocument(tempFile, replacements));
} protected String getFileContent(String filePath) {
String str_ret = "";
String line = null;
//Read file
try {
FileReader fr = new FileReader(filePath);
BufferedReader br = new BufferedReader(fr);
while ((line = br.readLine()) != null) {
str_ret += line + "\r\n";
}
br.close();
fr.close();
} catch (FileNotFoundException fnfe) {
System.out.println("File_not_found");
} catch (IOException ioe) {
System.out.println("IO_reading_error");
}
return str_ret;
} protected void setFileContent(String filePath, String content) {
try {
FileWriter fw = new FileWriter(filePath);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.flush();
bw.close();
fw.close();
} catch (IOException ioe) {
System.out.println("IO_writing_error");
}
}}读文本你试试,看有多长的文本它读不出来?这个是在linux环境下写的。window 下照样通过。