-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_conversation.java
More file actions
64 lines (56 loc) · 1.79 KB
/
file_conversation.java
File metadata and controls
64 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class file_conversation {
public static void main(String args[])throws Exception
{
File convo_f=new File("C:\\Users\\91630\\Downloads\\file conversation.txt");
try
{
String sentence;
File f_1 =new File("person_1.txt");
File f_2=new File("person_2.txt");
FileReader fr_txt=new FileReader(convo_f);
BufferedReader br_txt=new BufferedReader(fr_txt);
FileWriter fw =new FileWriter("person_1.txt");
FileWriter fw_1=new FileWriter("person_2.txt");
int num=0;
while((sentence=br_txt.readLine())!=null)
{
if(num % 2 == 0)
{
fw.write(sentence);
fw.write("\n");
}
else
{
fw_1.write(sentence);
fw_1.write("\n");
}
num+=1;
}
fw.close();
fw_1.close();
String str_1,str_2;
System.out.println("\n"+"---DISPLAY PERSON-1 CONVERSATION---"+"\n");
BufferedReader a = new BufferedReader(new FileReader(f_1));
while ((str_1 = a.readLine()) != null)
{
System.out.println(str_1);
}
System.out.println("\n"+"---DISPLAY PERSON-2 CONVERSATION---"+"\n");
BufferedReader b = new BufferedReader(new FileReader(f_2));
while ((str_2 = b.readLine()) != null)
{
System.out.println(str_2);
}
}
catch(FileNotFoundException e)
{
System.out.println("The specified file does not exist...");
}
}
}