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

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...