Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

write message in file java

// Java Program to Write Into a File
// using writeString() Method
 
// Importing required classes
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
 
// Main class
public class GFG {
 
    // Main driver method
    public static void main(String[] args)
        throws IOException
    {
        // Assigning the content of the file
        String text
            = "Welcome to geekforgeeks
Happy Learning!";
 
        // Defining the file name of the file
        Path fileName = Path.of(
            "/Users/mayanksolanki/Desktop/demo.docx");
 
        // Writing into the file
        Files.writeString(fileName, text);
 
        // Reading the content of the file
        String file_content = Files.readString(fileName);
 
        // Printing the content inside the file
        System.out.println(file_content);
    }
}
Comment

write message in file java

// Java Program to Write Into a File
// using writeString() Method
 
// Importing required classes
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
 
// Main class
public class GFG {
 
    // Main driver method
    public static void main(String[] args)
        throws IOException
    {
        // Assigning the content of the file
        String text
            = "Welcome to geekforgeeks
Happy Learning!";
 
        // Defining the file name of the file
        Path fileName = Path.of(
            "/Users/mayanksolanki/Desktop/demo.docx");
 
        // Writing into the file
        Files.writeString(fileName, text);
 
        // Reading the content of the file
        String file_content = Files.readString(fileName);
 
        // Printing the content inside the file
        System.out.println(file_content);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: main method in java 
Java :: get imei android programmatically android 10 
Java :: java stream sort 
Java :: do while jaca 
Java :: loop array using stream java 
Java :: open new fragment from fragment 
Java :: parcourir un string java 
Java :: java create arraylist with size 
Java :: Java get integer color from rgb 
Java :: java method overriding 
Java :: android get string value 
Java :: how to highlight text in android studio 
Java :: how to convert errorBody to pojo in retrofit 
Java :: constructor 
Java :: change text size java 
Java :: initialize mocks 
Java :: sorting methods in java 
Java :: overload and override in java 
Java :: hdfs hadoop JobClient.java:876 error 
Java :: java code for scientific calculator GUI 
Java :: get SecretKey from String 
Java :: how to read a table from text file in java 
Java :: euclidean algorithm java recursive 
Java :: set union java 
Java :: remove selected text from string value android java 
Java :: arraylist in java 
Java :: java csv compare 
Java :: array copy java 
Java :: java background color 
Java :: click on recyclerview item android animation 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =