Computer Science, asked by prabhatkumarsh9651, 1 year ago

Convert the json file to properties file in java

Answers

Answered by ana17129902
0

import java.util.*;

import java.io.*;

class FILE4

{

public static void main(String args[])throws Exception

{

Scanner s1=new Scanner(System.in);

FileOutputStream f1=new FileOutputStream("E:/A2.txt",true);

DataOutputStream d1=new DataOutputStream(f1);

char choice;

int rno;

String name;

do

{

System.out.println("Enter a roll number and name:");

rno=s1.nextInt();

name=s1.nextLine();

d1.writeInt(rno);

d1.writeUTF(name);

System.out.println("Continue???");

choice=s1.next().charAt(0);

}while(choice=='y'||choice=='Y');

System.out.println("DO YOU WANT TO READ THIS BINARY FILE??\nIF YES THEN TYPE 'YES' OTHERWISE TYPE 'NO'--->");

String ch=s1.next();

if(ch.equalsIgnoreCase("yes"))

{

try

{

FileInputStream F1=new FileInputStream("E:/A2.txt");

DataInputStream D1=new DataInputStream(F1);

boolean eof=true;

while(eof)

{

try

{

int rn=D1.readInt();

String nm=D1.readUTF();

System.out.println("ROLL NO.  "+rn+"\nNAME  "+nm);

}

catch(EOFException x)

{

eof=false;

}

}

}

catch(FileNotFoundException e)

{

System.out.println("File Does Not Found");

}

}

if(ch.equalsIgnoreCase("No"))

{

System.out.println("Byeee!!!!!");

System.exit(0);

}

FileOutputStream F=new FileOutputStream("E:/A3.txt",true);

DataOutputStream D=new DataOutputStream(F);

boolean e=true;

try

{

FileInputStream F1=new FileInputStream("E:/A2.txt");

DataInputStream D1=new DataInputStream(F1);

while(e)

{

int rns=D1.readInt();

String nms=D1.readUTF();

D.writeInt(rns);

D.writeUTF(nms);

}

}

catch(EOFException x)

{

e=false;

}

System.out.println("DO YOU WANT TO READ THE COPIED BINARY FILE??\nIF YES THEN TYPE 'YES' OTHERWISE TYPE 'NO'--->");

String ch1=s1.next();

if(ch.equalsIgnoreCase("yes"))

{

try

{

FileInputStream F12=new FileInputStream("E:/A3.txt");

DataInputStream D12=new DataInputStream(F12);

boolean eof=true;

while(eof)

{

try

{

int rnI=D12.readInt();

String nmI=D12.readUTF();

System.out.println("ROLL NO.  "+rnI+"\nNAME  "+nmI);

}

catch(EOFException x)

{

eof=false;

}

}

}

catch(FileNotFoundException x)

{

System.out.println("File Does Not Found");

}

}

if(ch.equalsIgnoreCase("No"))

{

System.out.println("Byeee!!!!!");

System.exit(0);

}

}

}

Similar questions