forked from Assasincoderzz/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2.java
82 lines (76 loc) · 2.87 KB
/
p2.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.io.*;
import java.util.*;
class FileCreation{
public void createFile() throws IOException {
String fileContent = "14 Ram [email protected] 9876543433 Afghanistan\r\n" +
"170 Janu [email protected] 9876543434 Albania\r\n" +
"197 Karthick [email protected] 9876543435 Algeria\r\n" +
"123 Kumar [email protected] 9876543436 Antarctica\r\n" +
"166 Gobi [email protected] 9876543443 Barbados\r\n" +
"116 Guru [email protected] 8876543444 Bermuda\r\n" +
"191 John [email protected] 9876543445 Brazil\r\n" +
"70 Sri [email protected] 9876543446 Canada\r\n" +
"175 Babu [email protected] 9876543447 Cuba\r\n" +
"55 vishal [email protected] 8876543449 Afghanistan\r\n" +
"136 Ravi [email protected] 9876543450 Albania\r\n" +
"76 Shyuam [email protected] 9876543451 Algeria\r\n" +
"10 Seetha [email protected] 9876543452 Antarctica\r\n" +
"47 Deepa [email protected] 9876543453 Barbados\r\n" +
"15 Keethir [email protected] 9876543454 Bermuda\r\n" +
"53 Kathir [email protected] 9876543455 Brazil\r\n" +
"104 Babu [email protected] 9876543456 Canada\r\n" +
"99 Prasanth [email protected] 9876543457 Cuba\r\n" +
"79 Reeha [email protected] 9876543437 Finland\r\n" +
"97 Smith [email protected] 9876543438 India\r\n" +
"173 rani [email protected] 9876543439 India\r\n" +
"168 Reeta [email protected] 9876543440 India\r\n" +
"32 raji [email protected] 9876543441 India\r\n" +
"11 vani [email protected] 9876543442 India";
FileWriter fileWriter = new FileWriter("File1.txt");
fileWriter.write(fileContent);
fileWriter.close();
}
}
public class p2{
public static void main(String args[]) throws IOException {
FileCreation fc =new FileCreation();
fc.createFile();
FileWriter writer = new FileWriter("File2.txt");
FileReader file = new FileReader("File1.txt");
BufferedReader br = new BufferedReader(file);
int[] arr = new int[24];
int i=0;
String line;
while((line = br.readLine()) != null)
{
String words[] = line.split(" ");
arr[i]=Integer.valueOf(words[0]);
i++;
}
Arrays.sort(arr);
br.close();
file.close();
for(int j=0;j<24;j++)
{
String line1;
FileReader file1 = new FileReader("File1.txt");
BufferedReader br1 = new BufferedReader(file1);
while((line1 = br1.readLine()) != null)
{
String words1[] = line1.split(" ");
if(arr[j]==Integer.valueOf(words1[0]))
{
writer.write(words1[1]+" "+words1[0]+" "+words1[2]+" "+words1[3]+" "+words1[4]+"\n");
}
}
br1.close();
file1.close();
}
writer.close();
File myObj =new File("File2.txt");
Scanner read = new Scanner(myObj);
while(read.hasNextLine()) {
System.out.println(read.nextLine());
}
}
}