如何用Java把一个文本中指定信息复制到另一个文本中
答案:4 悬赏:40 手机版
解决时间 2021-02-20 23:53
- 提问者网友:我是我
- 2021-02-20 16:54
如何用Java把一个文本中指定信息复制到另一个文本中
最佳答案
- 五星知识达人网友:行雁书
- 2021-02-20 17:25
JTextField t1 = new JTextField();
JTextField t2 = new JTextField();
t2.setText(t1.getText());
JTextField t2 = new JTextField();
t2.setText(t1.getText());
全部回答
- 1楼网友:山河有幸埋战骨
- 2021-02-20 20:16
import java.io.bufferedreader;
import java.io.bufferedwriter;
import java.io.file;
import java.io.fileinputstream;
import java.io.fileoutputstream;
import java.io.inputstreamreader;
import java.io.outputstreamwriter;
public class replacetext {
public static void main(string[] args ) throws exception {
file source = new file("d:/abc.txt");
bufferedreader in = new bufferedreader(new inputstreamreader(new fileinputstream(source)));
file desc = new file("d:/a.txt");
bufferedwriter out = new bufferedwriter(new outputstreamwriter(new fileoutputstream(desc)));
string str = null;
while ((str = in.readline()) != null) {
out.write(str + "\r\n");
}
out.close();
in.close();
}
}
- 2楼网友:忘川信使
- 2021-02-20 19:16
你好:
从A读取到B中:
import java.io.*;
public class IoDemo{
public static void main(String[] args)throws Exception{
String str = "";
File file1 = new File("D:\\A.txt");
File file2 = new File("D:\\B.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file1),"UTF-8"));
//读取
while (br.read()!=-1) {
str += br.readLine();
}
br.close();
br = new BufferedReader(new FileReader(file2));
str += br.readLine();
br.readLine();
//写入
BufferedWriter bw = new BufferedWriter(new FileWriter(file2));
bw.write(str);
bw.close();
}
}
- 3楼网友:渊鱼
- 2021-02-20 18:04
public static void copy() throws Exception{
FileInputStream fis = new FileInputStream("目录");
byte [] b = new byte[1024];
int n;
FileOutputStream fos = new FileOutputStream("目标位置");
while((n=fis.read(b))!=-1){
fos.write(b, 0, n);
}
fos.close();
fis.close();
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯