• About
  • Advertise
  • Privacy & Policy
  • Contact
iOSlift logo
  • Home
  • About
  • JailBreakMe
  • Services
  • Paid Services
  • Downloads
    • IOS 14 BEta IPSW
    • IOS 13 iPSW
    • TVPROfileOS
    • MacOS Profile Download
    • WatchOS Profile Configuration
No Result
View All Result
  • Home
  • About
  • JailBreakMe
  • Services
  • Paid Services
  • Downloads
    • IOS 14 BEta IPSW
    • IOS 13 iPSW
    • TVPROfileOS
    • MacOS Profile Download
    • WatchOS Profile Configuration
No Result
View All Result
iOSLift Logo White Mob
No Result
View All Result

Write a program that takes 3 numbers as input in a file and prints the contens of the file.

Faheem Ali by Faheem Ali
March 21, 2017
Home Uncategorized
Share on FacebookShare on Twitter

LAB#1

Filing & Calendar in java

 

LAB OBJECTIVE

1)      Write a program that takes 3 numbers as input in a file and prints the contens of the file.

Input:

package l2t1;

import java.io.*;

import java.util.Scanner;

public class L2t1 {

public static void main(String[] args) {

File f;

Scanner sc = new Scanner(System.in);

try{

byte m[] = new byte[3];

System.out.println(“Enter 3 number : “);

for(int i = 0; i < m.length ; i++){

m[i]= sc.nextByte();

}

f = new File(“C:/sss.txt”);

OutputStream os = new FileOutputStream(f);

for(int  i =0;i<m.length;i++){

os.write(m[i]);

}

os.close();

InputStream is = new FileInputStream(f);

int size = is.available();

for(int i= 0 ;i<size;i++){

System.out.println(is.read()+”  “);

}

}catch(Exception e){ System.out.println(“file not exist”);

}}}

Output:

Enter 3 number :

3

6

5

3

6

5

 

 

2)      Write a program that converts these numbers into character and print them.

Input:

package l2t2;

import java.io.*;

import java.util.Scanner;

public class L2t2 {

public static void main(String[] args) {

File f;

Scanner sc = new Scanner(System.in);

try{

byte m[] = new byte[3];

System.out.println(“Enter 3 number : “);

for(int i = 0; i < m.length ; i++){

m[i]= sc.nextByte();

}

f=new File(“C:/sss.txt”);

OutputStream os = new FileOutputStream(f);

for(int  i =0;i<m.length;i++){

os.write(m[i]);

}

os.close();

InputStream is = new FileInputStream(f);

int size = is.available();

for(int i= 0 ;i<size;i++){

//System.out.println(is.read()+”  “);

}

char c;

int s = is.available();

for(int x= 0;x<s;x++){

c = (char) is.read();

System.out.println(c);

}

}catch(Exception e){ System.out.println(“file not exist”);

}}}

OUTPUT

Enter 3 number :

66

67

68

B

C

D

 

3)      Write a program that takes string as input and write in file1.Copy the contents of file2 to file1 and print the contents of file1.

Input:

package l2t3;

import java.io.*;

import java.util.Scanner;

public class L2t3 {

public static void main(String[] args) {

File f;

File f2;

Scanner sc = new Scanner(System.in);

try{

byte m[] = new byte[3];

System.out.println(“Enter 3 number : “);

for(int i = 0; i < m.length ; i++){

m[i]= sc.nextByte();

}

f=new File(“C:/sss.txt”);

f2=new File(“C:/aaa.txt”);

OutputStream os = new FileOutputStream(f);

OutputStream oss = new FileOutputStream(f2);

for(int  i =0;i<m.length;i++){

os.write(m[i]);

}

InputStream is = new FileInputStream(f);

InputStream iss = new FileInputStream(f2);

int size = is.available();

for(int i= 0 ;i<size;i++){

oss.write(is.read());

System.out.println(iss.read()+”  “);

}

}catch(Exception e){ System.out.println(“file not exist”);

}}}

OUTPUT:

Enter 3 number :

67

68

69

67

68

69

 

 

 

HOME TASK

1)      Write a program that reads names from the given file “Names” and search for a specific initial letter in the names and write a new file “New Names” with these searched names.

Input:

package l2h1;

import java.io.*;

import java.util.Scanner;

public class L2h1 {

public static void main(String[] args) {

File f;

File f2;

char c,d,g;

Scanner sc = new Scanner(System.in);

System.out.print(“Enter initial letter to search for : “);

char v = sc.next().charAt(0);

try{

f=new File(“E:/names.txt”);

f2=new File(“E:/newnames.txt”);

InputStream is = new FileInputStream(f);

InputStream iss = new FileInputStream(f2);

OutputStream oss = new FileOutputStream(f2);

int size = is.available();

char str[] = new char[size];

System.out.print(“Names in file1 : “);

for(int i= 0 ;i<size;i++){

c = (char) is.read();

System.out.print(c);

str[i] = (char) c ;

}

System.out.println(“”);

for(int k = 0 ; k<size ; k++){

if(str[k] == v){

for(int j = 0; j < 6 ; j++){

oss.write(str[j]);

}

}}

int size2 = iss.available();

System.out.print(“Names in file2 : “);

for(int k = 0;k<size2;k++){

g = (char) iss.read();

System.out.print(g);

}}catch(Exception e){ System.out.println(“Either file not exist or Error is found!”);

}

}}

Output:

Enter initial letter to search for : s

Names in file1 : umair

Names in file2 : husssain

2)      Write a program that print total number of words in a file.

Input:

 

package l2h2;

import java.io.*;

import java.util.Scanner;

public class L2h2 {

public static void main(String[] args) {

File f;

String c;

char d;

int words = 0;

Scanner sc = new Scanner(System.in);

try{

f=new File(“C:/names.txt”);

InputStream is = new FileInputStream(f);

int size = is.available();

String str[] = new String[size];

System.out.print(“Data in file1 : “);

for(int i= 0 ;i<size;i++){

d = (char)is.read();

str[i] = Character.toString(d);

if(” “.equals(str[i])){

words++;

}

System.out.print(d);

}

System.out.println(“\nNumber of words in file : “+(words+1));

}catch(Exception e){ System.out.println(“Either file not exist or Error is found!”);

}}}

Output:

Data in file1 : ROSE

Number of words in file : 1

Previous Post

WAP that takes your name roll and fee as i/p and print them

Next Post

W.A.P that take an array of int type of size 50 Fill this array by multiple of 9 print it.

Faheem Ali

Faheem Ali

I'm A Student of Sir Syed University Here to Provide you News and Updates on iPhone , iPad , iPhone and Also The iMac & Apple iWatch

Next Post

W.A.P that take an array of int type of size 50 Fill this array by multiple of 9 print it.

Please login to join discussion
  • How To Fill Google AdSense MANAGE Tax Info in Pakistan

    HOW TO BYPASS IPHONE PTA TAX IN PAKISTAN

    555 shares
    Share 222 Tweet 139
  • All in One Automatic Roti Maker in Pakistan

    531 shares
    Share 212 Tweet 133
  • GymKit and Apple Watch: A Perfect Pair for Effective Workouts

    508 shares
    Share 203 Tweet 127
  • How To Do CPLC Mobile Check Step-By-Step Guide

    497 shares
    Share 199 Tweet 124
  • What is Chat CPT How it Works ?

    497 shares
    Share 199 Tweet 124
iOSlift logo

iOS lift provides Software Updates for Apple Products like iPhone, iPod , iPad & iMac

Follow Us

Categories

  • Apple
  • iPhone’s
  • iOS
  • Cydia Jaibreak
  • Computers
  • Business
  • Community
  • Education
  • Electric Car
  • Entertainment
  • Trending
  • Comments
  • Latest
How To Fill Google AdSense MANAGE Tax Info in Pakistan

HOW TO BYPASS IPHONE PTA TAX IN PAKISTAN

November 29, 2022
All in One Automatic Roti Maker in Pakistan

All in One Automatic Roti Maker in Pakistan

July 20, 2020
GymKit and Apple Watch

GymKit and Apple Watch: A Perfect Pair for Effective Workouts

December 8, 2023
CPLC Mobile Check

How To Do CPLC Mobile Check Step-By-Step Guide

December 2, 2023
Get Free: Game Show Aisay Chalay Ga Passes & Timings ,Registration

Get Free: Game Show Aisay Chalay Ga Passes & Timings ,Registration

78
Apple Releases Their New IOS 10.3 Beta 1 Public Preview

Apple Releases Their New IOS 10.3 Beta 1 Public Preview

9
How To Get PAKISTAN V WORLD XI T20 Cricket Match Tickets

Pakistan Super League 2018 Schedule

6

MacOS Beta Profile Error “you must enroll your Mac to download the beta” when trying to download the update?

5
italian food san antonio

Italian Food in San Antonio: Discover the Best Spots for Authentic Italian Cuisine

November 2, 2024
GymKit and Apple Watch

GymKit and Apple Watch: A Perfect Pair for Effective Workouts

December 8, 2023
Apple iOS 17.1.2 Unleashed: Discover the Latest Update’s Exciting New Features!

Apple iOS 17.1.2 Unleashed: Discover the Latest Update’s Exciting New Features!

December 2, 2023
CPLC Mobile Check

How To Do CPLC Mobile Check Step-By-Step Guide

December 2, 2023
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 iOS Lift All Rights Reserved Umair Ahmed.

No Result
View All Result
  • JailBreakMe
  • Services
  • Paid Services
  • MacOS Profile Download
    • TvOS Profile Confiuration
    • TVPROfileOS
    • WatchOS Profile Configuration
  • Privacy Policy
  • Contact Us
  • About

© 2023 iOS Lift All Rights Reserved Umair Ahmed.

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
x

Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0