已经对读取的文经过处理,现在想把它存入另一个一个文,应该用什么命令,请各位大侠帮忙!

silversnowjing 2004-09-17 04:16:06
如果,这是实现对一个文本文件的处理,然后输出,现在想把它存入另一个文应该怎么做!我的代码如下:问题解决即结贴给分,在线等!
package ReadFileA;
import java.util.*;
import java.io.*;

public class ReadFileA1 {
public ReadFileA1() {
}

public static void main(String args[]){
ReadFileA1 test = new ReadFileA1();
String strfile = ".\\data\\from.txt";
vctValue = test.ReadFile(strfile) ;
System.out.println("In File" + strfile + " : " ) ;

for (int i=0; i<vctValue.size() ; i++){
System.out.println( vctValue.get(i) ) ;
}
}

private Vector ReadFile(String strInFile) {
Vector vctInFile = new Vector() ;
String strLine = "" ;
int intLoop ;
//捕捉异常
try {
BufferedReader bfrdInFile = new BufferedReader(new FileReader(strInFile));
strLine = bfrdInFile.readLine();
intLoop = 0 ;

while (strLine != null) {
strLine = strLine.trim() ;
//
if ( strLine.equals("") ){
strLine = bfrdInFile.readLine();
continue ;
}

if(strLine.startsWith("<")) {
strLine = bfrdInFile.readLine();

intloop++ ;
}
else {
vctInFile.add( intLoop, strLine ) ;
intLoop++ ;
}

strLine = bfrdInFile.readLine();

}
bfrdInFile.close();
}

catch (Exception e) {
e.printStackTrace() ;
}


return vctInFile;
}
}

...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
silversnowjing 2004-09-22
  • 打赏
  • 举报
回复
唉呀
redlaputa 2004-09-17
  • 打赏
  • 举报
回复
import java.io.*;
import java.util.*;

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


BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("p1.java")));
DataOutputStream dos=new DataOutputStream(new FileOutputStream("pp.java"));
String str;Object o;
//while(br.ready())
while((str=br.readLine())!=null)
{

l.add(str);
//System.out.println(str);
}
//ListIterator it=l.listIterator();
int i=1;
while ((o=l.removeLast())!=null)
{
System.out.println((String)o);
dos.writeBytes(i+" "+(String)o+"\n");
i++;
}



while(it.hasNext())
{
System.out.println((String)it.next());
}
while(it.hasPrevious())
{
System.out.println((String)it.previous());
}
*/
//System.out.println("Hello World!");
}
catch (Exception e)
{
}

}
}
bovy 2004-09-17
  • 打赏
  • 举报
回复
FileWriter fOut = null;
try
{
fOut = new FileWriter(file);
String fileContent = "文件内容";
fOut.write(fileContent);
fOut.close();
fOut = null;
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
catch(IOException eIO)
{
eIO.printStackTrace();
}
finally
{
if (null != fOut)
{
try {
fOut.close();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
treeroot 2004-09-17
  • 打赏
  • 举报
回复
会读怎么就不会写呢?
其实是一样的,不就是吧Reader改为Writer吗?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧