Import java.io.bufferedreader;
Import java.io.bufferedwriter;
import Java . io . filenotfoundexception;
Import java.io.filereader;
Import java.io.filewriter;
Import java.io.ioexception;
Public class Test 1 {
//Write data to a file
Public static void writeToFile (string path)
Try {
buffered writer bw = new buffered writer(new file writer(path));
int a = 100;
int b = 200
//You need to convert plastic into string type.
bw . write(string . value of(a));
bw . flush();
bw . newline();
bw . flush();
bw . write(string . value of(b));
bw . flush();
bw . close();
} catch (IOException e) {
e . printstacktrace();
}
}
//Open the file and display the contents of the file to the console.
Public static void readFile (string path)
Try {
buffered reader br = new buffered reader(new file reader(path));
Try {
String line = null
while((line = br.readLine())! = null){
system . out . println(line);
}
} catch (IOException e) {
e . printstacktrace();
}
} catch(file not found exception e){
e . printstacktrace();
}
}
Public static void main(String[] args) {
write to file(" d:/sample . dat ");
readFile(" d:/sample . dat ");
}
}