Lesson 7 - String and IO
Lesson 7 - String and IO
String and IO
IO handling
Because of that
• A file is a
– collection of perticular records
– located in the secondary storage
– What is a record?
• A collection of several fields, where a field consists of charactors.
– A File can be
• Created, manipulated, updated, etc in Java.
IO handling (cont.)
• Two groups
– Byte stream classes
– Charactor stream classes
• Refer www.javapoint.com
Create and write a simple file
import java.io.FileOutputStream;
public class FileOperations1 {
inputFile.close();
System.out.println("File operation is successful...");
}catch(Exception e){
System.out.println(e);
import java.io.FileInputStream
}
String
System.out.println(sentence1+"->"+sentence1.toLowerCase());
System.out.println(sentence1+"->"+sentence1.toUpperCase());
System.out.println(sentence1+"->"+sentence1.replace('e','a'));
System.out.println(sentence1.trim()+"->"+sentence1); Hello World
Java
String sentence3 = sentence1.concat(sentence2); Hello World ->hello world
Hello World ->HELLO WORLD
System.out.println(sentence3);
Hello World ->Hallo World
System.out.println(sentence1.substring(6)); Hello World->Hello World
System.out.println(sentence1.substring(2,4)); Hello World Java
System.out.println("index of o "+sentence1.indexOf('o')); World
ll
System.out.println("index of o "+sentence1.indexOf('o',5));
index of o 4
index of o 7
String Buffer
www.abc.com/create/user
www.abc>>Added<<.com/create/user
www.abc>>Added<<.com/create/user>>Added to the End<<<