Announcements - PowerPoint PPT Presentation

About This Presentation
Title:

Announcements

Description:

... // System.in is the keyboard file Input Files import java.io.*; import java.util.Scanner; class FileInput { public static void main(String [ ] args) ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 8
Provided by: Jon1158
Learn more at: http://www.cs.iit.edu
Category:

less

Transcript and Presenter's Notes

Title: Announcements


1
Announcements
  • Quiz 2 Grades Posted on blackboard

2
Files
  • Data in Main Memory is volatile
  • File Place for permanent data storage
  • C drive, A drive, Flash drive, etc.

Main Memory
File
main() int num string firstname
Disk
3
Scanner Input
  • Scanner scan new Scanner(System.in)
  • while (scan.hasNextInt())
  • i scan.nextInt()
  • // System.in is the keyboard file

4
Input Files
data.txt file
  • import java.io.
  • import java.util.Scanner
  • class FileInput
  • public static void main(String args) throws
    IOException
  • File ifile new File("data.txt")
  • Scanner scan new Scanner(ifile)
  • while (scan.hasNextInt())
  • i scan.nextInt()

17 6 432
5
Display Output
  • for (i0i lt 100 i i 2)
  • System.out.println(i)
  • // System.out is the display window file

6
Output File Streams
data2.txt
0 2 98
  • import java.io.
  • class FileOutput
  • public static void main(String args) throws
    IOException
  • int i
  • FileOutputStream ofile new FileOutputStream("da
    ta2.txt",false) //trueAPP
  • PrintWriter pw new PrintWriter(ofile)
  • for (i0i lt 100 i i 2)
  • pw.println(i)
  • pw.close() // Writes data to file on disk

7
  • import java.util.Scanner
  • import java.io.
  • class FormatFileData
  • public static void main(String args) throws
    IOException
  • int loops, integer, i
  • float decimal
  • String name
  • File ifile new File("mydata.txt")
  • Scanner scan new Scanner(ifile)
  • loops scan.nextInt()
  • for(i 0 i lt loops i)
  • integer scan.nextInt()
  • decimal scan.nextFloat()
  • name scan.next()

mydata.txt file 5 8 9.3 Jon 6 14.335 Bill 0
35.67e9 Mary -23 -4.55 Smith -3 -4e3 xyz
Output
8 9.3 Jon 6 14.335 Bill 0 3.567E10 Mary -23
-4.55 Smith -3 4000.0 xyz
Write a Comment
User Comments (0)
About PowerShow.com