java csv 换行符_有关Java 文件读取中换行的问题

为何每次运行这个函数后所得到的新文件中,原来的内容每行第一个字符没有读入,例如原文件为:10000abc1231005.12调用该函数并添加新的文本后,此文件就变为:1000bc2300.12......pub...

为何每次运行这个函数后所得到的新文件中,原来的内容每行第一个字符没有读入,例如原文件为:

10000

abc

123

100

5.12

调用该函数并添加新的文本后,此文件就变为:

1000

bc

23

00

.12

......

public void addStock(JMenuBar jmb){

String fileName ="C:\\Stock.doc";

String temp1,temp2,temp3,temp4;

String balance="";

StringBuffer content = new StringBuffer();

float n,f1,f2;

temp1=JOptionPane.showInputDialog("Please input stock name");

temp2=JOptionPane.showInputDialog("Please input stock code");

temp3=JOptionPane.showInputDialog("Please input how many shares you buy");

n=Float.parseFloat(temp3);

temp4=JOptionPane.showInputDialog("Please input share price");

f1=Float.parseFloat(temp4);

try{

BufferedReader in = new BufferedReader(new FileReader(fileName));

balance=in.readLine();

while(in.read()!=-1){

content.append(in.readLine()+'\n');

}

in.close();

}

catch(IOException ioe){

System.out.println("Problem reading "+fileName);

}

f2=Float.parseFloat(balance);

if(f2-f1*n<0){

JOptionPane.showMessageDialog(jmb,"Not enough balance!");

return;

}

try{

BufferedWriter out = new BufferedWriter(new FileWriter(fileName));

out.write(new String().valueOf(f2-f1*n));

out.newLine();

out.write(new String(content));

out.newLine();

out.write(temp1);

out.newLine();

out.write(temp2);

out.newLine();

out.write(temp3);

out.newLine();

out.write(temp4);

out.newLine();

out.close();

}

catch(IOException ioe){

System.out.println("Problem writing C:\\Stock.doc");

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值