import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Serializable;

public class ObjectStreamDemo
{
	static String[] arr = new String[100];
	static String[] arr1 = new String[100];
	static String[] arr2 = new String[100];

	static String path1 = "F:\\新建文件夹\\题目内容.txt";
	static String newPath = "F:\\题目内容.txt";

	public static void main(String[] args) throws Exception
	{

		readTxt(path1);
		// actionMode();

		Paper p1 = new Paper();
		p1.setTopic(arr[0]);
		p1.setAnswer(arr1[0]);
		Paper p2 = new Paper();
		p2.setTopic(arr[1]);
		p2.setAnswer(arr1[1]);
		Paper p3 = new Paper();
		p3.setTopic(arr[2]);
		p3.setAnswer(arr1[2]);
		Paper p4 = new Paper();
		p4.setTopic(arr[3]);
		p4.setAnswer(arr1[3]);
		Paper p5 = new Paper();
		p5.setTopic(arr[4]);
		p5.setAnswer(arr1[4]);

		writeMode(p1);
		writeMode(p2);
		writeMode(p3);
		writeMode(p4);
		writeMode(p5);

		for (int i = 0; i < arr.length; i++)
		{
			System.out.println(arr[i]);
			System.out.println(arr1[i]);
		}
	}

	@SuppressWarnings("resource")
	public static void readTxt(String path2) throws Exception
	{

		Reader reader = new FileReader(path2);;
		BufferedReader bufr = new BufferedReader(reader);

		StringBuffer buf = new StringBuffer();
		String line = null;
		String s = null;
		int k = 0;
		while ((line = bufr.readLine()) != null)
		{

			if (line.contains("答案"))
			{
				arr1[k] = line;
				line = "aaaaa";
				k++;
			}
			buf.append(line + "\r\n");
		}
		s = buf.toString();
		arr2 = s.split("aaaaa");
		for (int j = 0; j < arr2.length; j++)
		{
			arr[j] = arr2[j];
		}
		bufr.close();
	}

	public static void writeMode(Object obj) throws Exception
	{
		ObjectOutputStream oos = null;
		OutputStream out = new FileOutputStream(newPath);
		oos = new ObjectOutputStream(out);
		oos.writeObject(obj);
		oos.close();
	}
}

class Paper implements Serializable
{
	private String topic;
	private String answer;

	public String getTopic()
	{
		return this.topic;
	}

	public void setTopic(String topic)
	{
		this.topic = topic;
	}

	public String getAnswer()
	{
		return this.answer;
	}

	public void setAnswer(String answer)
	{
		this.answer = answer;
	}
}