Friday, 16 September 2016

Java program to Merge the Splited File

import java.io.*;
class Merger
{
public static void main(String[] args) throws IOException
{
Console con=System.console();
System.out.print("Enter destination file name : ");
String fname=con.readLine();
File f=new File(fname);
if (f.exists())
f.delete();

FileOutputStream fos=new FileOutputStream(fname);
int i=0;
File f1=null;
while (true)
{
f1=new File(""+i+f);
if (!f1.exists())
{
break;
}
FileInputStream fis=new FileInputStream(f1);
int ch;
while((ch=fis.read())!=-1)
fos.write((char)ch);
fis.close();
f1.delete();
i++;
}
}
}

Java program to Split a file

import java.io.*;
class SplitFile
{
public static void main(String[] args) throws IOException
{
String fname;
int size, count, no, total=0, rem;
Console con=System.console();
System.out.print("Enter file name : ");
fname=con.readLine();

File f=new File(fname);
if (f.exists())
{
System.out.println("Size of the file is "+f.length());
total=(int)(f.length());
}
else
{
System.out.print("Source file does not exists.");
System.exit(0);
}

System.out.print("Enter destination file size : ");
size=Integer.parseInt(con.readLine());
no=total/size;
rem=total%size;

if (rem>0)
no+=1;
FileInputStream fis=new FileInputStream(f);
File file;
int ch;
for(int i=0;i<no;i++)
{
FileOutputStream fos=new FileOutputStream(""+i+f);
count=1;
while((ch=fis.read())!=-1)
{
fos.write(ch);
count++;
if (count>size)
{
fos.close();
break;
}
}
}
fis.close();
}
}

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...