如何用Java将某一文件中的数据随机不重复写入另一文件中
文件为txt文件,数据是按行划分的,共有2860行,格式如:31:-732:-553:-594:-485:-4131:-712:-553:-584:-485:-4141:...
文件为txt文件,数据是按行划分的,共有2860行,格式如:
3 1:-73 2:-55 3:-59 4:-48 5:-413 1:-71 2:-55 3:-58 4:-48 5:-41 4 1:-75 2:-59 3:-50 4:-44 5:-434 1:-75 2:-59 3:-50 4:-44 5:-43
5 1:-75 2:-51 3:-50 4:-50 5:-36 5 1:-75 2:-51 3:-50 4:-50 5:-36
6 1:-70 2:-52 3:-55 4:-57 5:-386 1:-70 2:-52 3:-55 4:-57 5:-38 展开
3 1:-73 2:-55 3:-59 4:-48 5:-413 1:-71 2:-55 3:-58 4:-48 5:-41 4 1:-75 2:-59 3:-50 4:-44 5:-434 1:-75 2:-59 3:-50 4:-44 5:-43
5 1:-75 2:-51 3:-50 4:-50 5:-36 5 1:-75 2:-51 3:-50 4:-50 5:-36
6 1:-70 2:-52 3:-55 4:-57 5:-386 1:-70 2:-52 3:-55 4:-57 5:-38 展开
1个回答
展开全部
import java.util.*;
import java.math.*;
import java.text.*;
import java.io.*;
class baidu
{
public static void main(String[] args) throws Exception
{
BufferedReader bufr=new BufferedReader(new FileReader("a.txt"));
String line=null;
List<String> list=new ArrayList<String>();
while((line=bufr.readLine())!=null)
{
list.add(line);
}
Collections.shuffle(list);
BufferedWriter bufw=new BufferedWriter(new FileWriter("b.txt"));
for(int i=0;i!=list.size();++i)
{
bufw.write(list.get(i));
bufw.newLine();
}
bufr.close();bufw.close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询