SlideServe
Menu
Préférences
© SlideServe · v2026

“Introduction to Programming With Java”

melva avatar
11 diapositives · 323 Views · Jun 07, 2012

“Introduction to Programming With Java”. Lecture - 16 U MESH P ATIL (umesh@cse.iitb.ac.in). nlp-ai@cse.iitb. Contents for Today’s Lecture. Revision of File-Reading Writing to files Example programs on file handling. nlp-ai@cse.iitb. Revision of File-Reading .

“Introduction to Programming With Java” - slide 1
01 / 11“Introduction to Programming With Java”
1 / 17

Télécharger la présentation

“Introduction to Programming With Java”
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. “Introduction to Programming With Java” Lecture - 16 UMESHPATIL (umesh@cse.iitb.ac.in) nlp-ai@cse.iitb

  2. Contents for Today’s Lecture • Revision of File-Reading • Writing to files • Example programs on file handling nlp-ai@cse.iitb

  3. Revision of File-Reading • Commands for opening the file for reading: • FileReader fr = new FileReader(“input.txt”);BufferedReader br = new BufferedReader(fr); • Command for reading one line from the opened file: • String str = br.readLine(); • Command for closing the opened file: • br.close(); nlp-ai@cse.iitb

  4. FileRead.java nlp-ai@cse.iitb

  5. File-Writing • Commands for opening the file for writing: • FileWriter fw = new FileWriter(“output.txt”);BufferedWriter bw = new BufferedWriter(fr); • Command for writing a String to the opened file: • bw.write(str); // str is a String • Command for closing the opened file: • bw.close(); nlp-ai@cse.iitb

  6. FileWrite.java nlp-ai@cse.iitb

  7. Examples • Write a File-Copy program which copies the content of one file to another. Take both the file names from the user. • Write a Java program for expanding abbreviations in the input text. Store the expanded output in one file. Input text is read from a file. Get the input and output file names from the user. Abbreviations along with their expansions are stored in the file ‘abbreviations.txt’ in the format:<line i>abbreviation<line i+1>expansion nlp-ai@cse.iitb

  8. ExpandAbbreviation Algorithm • Read abbreviations & expansions from file and store in arrays • Open input file for reading • Open output file for writing • For each line in the input file • Search for each abbreviation in the line and replace if found(find_and_replace() function) • Write the modified line to the output file • Close all opened files nlp-ai@cse.iitb

  9. ExpandAbbreviation.java nlp-ai@cse.iitb

  10. Exercise • Write a Java program for reading a dictionary file for counting the no. of dictionary entries in the file. Each line in the file consists of one dictionary entry. nlp-ai@cse.iitb

  11. End Thank you  nlp-ai@cse.iitb