-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitter.java
More file actions
55 lines (55 loc) · 1.09 KB
/
Copy pathsplitter.java
File metadata and controls
55 lines (55 loc) · 1.09 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
import java.io.*;
import java.util.Scanner;
class splitter
{
public splitter(File file,long s,long length,long t)throws IOException
{
FileInputStream fis=new FileInputStream(file);
int i,ch;
int c=0,n=0;
for(i=0;i<=t;i++)
{
n++;
}
System.out.println(n);
String str2=file.getName();
String str3=new String();
FileOutputStream fos[]=new FileOutputStream[n];
for(i=0;i<n;i++)
{
str3=(i+"."+str2);
fos[i]=new FileOutputStream(str3);
}
i=0;
while(i<n)
{
while((ch=fis.read())!=-1)
{
fos[i].write(ch);
c++;
if(c>s-1)
{
c=0;
break;
}
}
i++;
}
file.delete();
fis.close();
}
public static void main(String args[])throws IOException
{
Scanner sc=new Scanner(System.in);
System.out.println("enter file name");
String str=sc.nextLine();
File file=new File(str);
long length=file.length();
System.out.println("length is:"+length);
System.out.println("enter destination file size");
long s=sc.nextInt();
long t=(length/s);
System.out.println("no. of file is:"+t);
splitter k=new splitter(file,s,length,t);
}
}