package IO;

import java.io.*;

public class test {
	
	public  void connectWords(File file1, File file2, File file3)throws IOException
	{
		String[] str1 = split(file1, "\n");
		String[] str2 = split(file2, "\n"+"|"+" ");
		try(FileWriter fw = new FileWriter(file3))
		{	
			int index = 0;
			while(index != str1.length||index != str2.length)
			{
				if(index < str1.length)
					fw.write(str1[index]);
				if(index < str2.length)
					fw.write(str2[index]);
				index ++;
			}
		}
	}
	
	public String[] split(File f, String regex)throws IOException
	{
		try(FileReader fr = new FileReader(f))
		{
			char[] cbuf = new char[(int)f.length()];
			int hasRead = fr.read(cbuf);
			String str = new String(cbuf, 0, hasRead);
			String[] strArr = str.split(regex);
			return strArr;
		}
	}
	public static void main(String[] args) throws IOException
	{
		File f1 = new File("./a.txt");
		File f2 = new File("./b.txt");
		File f3 = new File("./c.txt");
		test t = new test();
		t.connectWords(f1, f2, f3);
	}
	
}

 

相关文章:

  • 2022-02-11
  • 2021-11-23
  • 2021-11-02
  • 2022-12-23
  • 2022-01-24
  • 2021-06-08
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案