Posts

Showing posts from February, 2019

How to read Array using For loop

public class OpenFile { public static void main(String args[]) { int arr[] = new int [ 5 ]; for ( int i = 0 ; i < arr. length ; i++) { arr[i] = i; System. out .println(arr[i]); } } } outpu: 0 1 2 3 4

How to open any file using java

We need File and Desktop modules for this program import java.awt.*; import java.io.File; import java.io.IOException; public class OpenFile { public static void main(String args[]) { File f = new File( "filepath.exe" ); Desktop d = Desktop. getDesktop (); try { d.open(f); } catch (IOException i) { System. out .println(i); } } }

How to read text file using java

Read text file using BufferedReader class. import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class readtxt { public static void main(String args[]) { try { File f = new File( "d:/file.txt" ); BufferedReader bf = new BufferedReader( new FileReader(f)); while (bf.read() != - 1 ) { System. out .println(bf.readLine()); } } catch (IOException i) { System. out .println(i); } } }

Welcome

This is my first post here. You are welcome.