Repository navigation
Expand file tree
/
Copy pathsplit.java
More file actions
73 lines (67 loc) · 2.08 KB
/
Copy pathsplit.java
File metadata and controls
73 lines (67 loc) · 2.08 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
package com.navdeep;
import java.io.*;
import java.util.Scanner;
public class split {
public void runn(String f) {
try {
// Reading file and getting no. of files to be generated
String inputfile = "D://navdeep/New file/" + f; // Source File Name.
double nol = 799999.0; // No. of lines to be split and saved in
// each output file.
File file = new File(inputfile);
Scanner scanner = new Scanner(file);
int count = 0;
System.out.println("-->Read started<--");
while (scanner.hasNextLine()) {
scanner.nextLine();
count++;
}
System.out.println("-->>>>>>Read ends here<<<<<<<--");
System.out.println("Lines in the file: " + count); // Displays no.
// of lines in
// the input
// file.
double temp = (count / nol);
int temp1 = (int) temp;
int nof = 0;
if (temp1 == temp) {
nof = temp1;
} else {
nof = temp1 + 1;
}
System.out.println("No. of files to be generated :" + nof); // Displays
// no.
// of
// files
// to be
// generated.
System.out.println("File:" + f);
// Actual splitting of file into smaller files
FileInputStream fstream = new FileInputStream(inputfile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
for (int j = 1; j <= nof; j++) {
FileWriter fstream1 = new FileWriter(
"D://navdeep/New file/Splitted_File" + j + ".txt"); // Destination
// File
// Location
BufferedWriter out = new BufferedWriter(fstream1);
for (int i = 1; i <= nol; i++) {
strLine = br.readLine();
if (strLine != null) {
out.write(strLine);
if (i != nol) {
out.newLine();
}
}
}
out.close();
}
in.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
System.out.println("This Process ends here");
}
}