Download presentation
Presentation is loading. Please wait.
Published byDennis Walker Modified over 9 years ago
1
IST 256 Application Programming for Information Systems Xiaozhong Liu Yatish Hegde https://xliu12.mysite.syr.edu/
2
Hard Disk (Secondary Memory) Memory (Primary Memory) Read Write Process
3
Input Stream Output Stream Default input/output streams
4
JAVA provides 2 types of streams Text streams - containing ‘characters‘ I ‘M A STRING\n ProgramDevice Binary Streams - containing 8 – bit information 01101001 ProgramDevice 1110110100000000
5
Create a stream object and associate it with a disk-file Give the stream object the desired functionality while there is more information read(write) next data from(to) the stream close the stream
6
public static void readFile() { BufferedReader ins = new BufferedReader(new FileReader(“test.txt”)); while(ins.ready()) { String s = ins.readLine(); System.out.println(s); } ins.close(); } Important: Place the code inside Try{…} Catch{….} Wherever necessary import java.io.*;
7
public static void writeFile() { String s = “I love programming”; BufferedWriter outs = new BufferedWriter(new FileWriter(“test_out.txt”)); outs.write(s); } outs.close(); Important: Place the code inside Try{…} Catch{….} Wherever necessary import java.io.*;
8
Public static void readFile() { BufferedReader ins = new BufferedReader(new FileReader(“test.txt”)); Scanner scanner = new Scanner(ins); while(scanner.hasNext()) { System.out.println(scanner.next()); } scanner.close(); } Important: Place the code inside Try{…} Catch{….} Wherever necessary import java.io.*; Import java.util.Scanner;
9
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser fc = new JFileChooser(); if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String inputFilePath = file.getAbsolutePath().toString(); jTextField1.setText(inputFilePath); }
10
In a notepad, type few sentences and save the file as test.txt. Write a Java program to read the text in test.txt and write that to file test_out.txt. In a notepad, type 10 numbers (any numbers in the range 0 to 10) separated by white space and save the file as grade.txt. Write a Java program to read the numbers from grade.txt, calculate the average grade and print the output. In a notepad, type five names (one name per line) and save the file as name.txt. Create a GUI from which you can select (browse button) the file name.txt and write (create button) the names in name.txt to file name_out.txt (one name per line).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.