java 更改文件内容
发布网友
发布时间:2022-04-22 11:25
我来回答
共3个回答
热心网友
时间:2023-09-22 01:05
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
public class FileInOutput {
/**
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("d:\\tt.cvs"));
File f = new java.io.File("d:\\mm.cvs");
FileOutputStream fos = new FileOutputStream(f);
OutputStreamWriter osw = new OutputStreamWriter(fos);
if(osw == null) System.out.println("osw is null");
br.readLine();
int c = 0;
while(true)
{
c = br.read();
if(c == -1) break;
if(c =='\"') continue;
osw.write(c);
}
br.close();
osw.close();
fos.close();
System.out.println("操作完成");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
热心网友
时间:2023-09-22 01:05
大致如下:
BufferedReader fp = new BufferedReader (new FileInputStream ("filename.csv")) ;
FileWriter o = new FileWriter ("newfile.csv") ;
String line = null ;
while ((line = fp.readLine ()) != null)
{
String s = line.replace ("\"" , "") ;
o.write (s) ;
o.write ("\\O\r\n") ;
}
fp.close () ;
o.flush () ;
o.close () ;
热心网友
时间:2023-09-22 01:06
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("tt.cvs")));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("mm.cvs")), true);
String buf = null;
int count = 0;
while((buf = br.readLine()) != null) {
if (count > 0) {
buf = buf.replace("\"", "");
pw.println(buf);
}
count++;
}
br.close();
pw.close();