Department of Computer Science(I.
T)
Lyallpur KhalsaCollege,Jalandhar
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
[Link] a program to copy characters from file named “[Link]” into a file called
“[Link]”
import [Link].*;
public class CopyFile {
public static void main(String args[]) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("[Link]");
out = new FileOutputStream("[Link]");
int c;
while ((c = [Link]()) != -1) {
[Link](c);
}
}finally {
if (in != null) {
[Link]();
}
if (out != null) {
[Link]();
}
}
}
}
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
[Link] a program to copy bytes from one file to another.
import [Link].*;
class CopyBytes
{
public static void main(String[] args)
{
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream("[Link]");
fos = new FileOutputStream("[Link]");
int ch;
while((ch=[Link]())!=-1){
[Link](ch);
}
}catch(IOException e)
{
[Link](e);
[Link](-1);
}
finally{
try{
[Link]();
[Link]();
}
catch(IOException e){}
}
}}
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
[Link] a program to sort an array of strings in alphabetical order.
public class Ordering{
static String[] cities = {"Delhi", "Mumbai", "Agra", "Chennai", "Jalandhar", "Jabalpur"};
public static void main(String[] args) {
int n = [Link];
String temp = null;
[Link]("Citites before sort");
for (int i = 0; i < n; i++) {
[Link](cities[i]);
}
[Link]("\n===========\n");
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (cities[i].compareTo(cities[j]) > 0) {
temp = cities[i];
cities[i] = cities[j];
cities[j] = temp;
}
}
}
[Link]("Citites after sort");
for (int i = 0; i < n; i++) {
[Link](cities[i]);
}
}
}
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
LKC/[Link]. (I.T) IV-Sem./2017/10531
Department of Computer Science(I.T)
Lyallpur KhalsaCollege,Jalandhar
[Link] a program to demonstrate the use of some string methods that are used for
manipulating strings.
public class String2{
public static void main(String args[]) {
String text = "hellothere";
int index = [Link](5);
int indexOf = [Link]('e');
[Link]("Length of " + text + " is "+[Link]());
[Link]("ASCII value : " + index);
[Link]("\nFirst index of 'e' : " + indexOf);
[Link]("Sub String:"+[Link](2,5));
for(int i = 0; i < [Link](); i++){
[Link]("Char at " + i + " is " + [Link](i));
}
}
}
LKC/[Link]. (I.T) IV-Sem./2017/10531