Sunday, April 29, 2018

Write the data in a file using Files class !!

Using Files class:
  1. import java.nio.file.Files;
  2. import java.nio.file.Paths;
  3. import java.nio.file.Path;
  4. import java.io.IOException;

  5. public class WriteByFiles {
  6. public static void main(String[] args) throws IOException {
  7. String content = "writing data to data1.txt file using Files class !!";
  8. String uri = "D:\\data1.txt";
  9. Path path = Paths.get(uri);
  10. Files.write(path, content.getBytes());
  11. }
  12. }
Output:
writing data to data1.txt file using Files class !!

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...