-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
130 lines (99 loc) · 3.32 KB
/
Copy pathMain.java
File metadata and controls
130 lines (99 loc) · 3.32 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.company;
import java.io.*;
import java.util.Scanner;
import java.util.*;
public class Main {
public static long getLineCount(File file) throws IOException {
try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(file), 1024)) {
byte[] c = new byte[1024];
boolean empty = true,
lastEmpty = false;
long count = 0;
int read;
while ((read = is.read(c)) != -1) {
for (int i = 0; i < read; i++) {
if (c[i] == '\n') {
count++;
lastEmpty = true;
} else if (lastEmpty) {
lastEmpty = false;
}
}
empty = false;
}
if (!empty) {
if (count == 0) {
count = 1;
} else if (!lastEmpty) {
count++;
}
}
return count;
}
}
public static void main(String[] args) throws IOException {
String namef = "notes1.txt";
//System.out.print(getLineCount("C:\\Users\\Alina\\IdeaProjects\\Massive\\m.txt"));
int count1=0;
try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(namef), 2048)) {
byte[] c = new byte[2048];
boolean empty = true,
lastEmpty = false;
//int count1 = 0;
int read;
while ((read = is.read(c)) != -1) {
for (int i = 0; i < read; i++) {
if (c[i] == '\n') {
count1++;
lastEmpty = true;
} else if (lastEmpty) {
lastEmpty = false;
}
}
empty = false;
}
if (!empty) {
if (count1 == 0) {
count1 = 1;
} else if (!lastEmpty) {
count1++;
}
}
// return count;
} catch(Exception e){}
System.out.print("\n Строк\n");
System.out.println(count1);
//D:\Massive\ip_addresses
// FileReader input = new FileReader(namef);
// LineNumberReader count = new LineNumberReader(input);
// while (count.skip(Long.MAX_VALUE) > 0) {
// }
// Long l1 = Long.parseUnsignedLong("17916881237904312345");
// Long l1 = count.getLineNumber();
// System.out.println("Строк " + l1);
File f = new File(namef);
System.out.println(f.exists());
Scanner scanner = new Scanner(f);
String[] myInts = new String[count1];
int mySpot = 0;
while (scanner.hasNext()) {
myInts[mySpot] = scanner.next();
mySpot++;
}
Arrays.sort(myInts);
int x = 0;
int y=0;
for (int i=0; i<count1-1; i++){
if(myInts[i].equals(myInts[i+1])){
x=x+1;
}
else {
y=y+1;
}
}
System.out.print("\n Повтор\n");
System.out.println(x);
System.out.print("\n Не повтор\n");
System.out.println(y+1);
}
}