Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

ASCII PrintWriter java.io examples

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintWriter;

    public class test {
    public static void main(String args[]){
                                  //Supposed to:
        writeFile("./test.txt"); //write ASCII 147
        readFile("./test.txt"); //read ASCII 147
    }

    public static boolean writeFile(String path){
        try{
            PrintWriter fo = new PrintWriter(new FileOutputStream(new File(path)));
            fo.print((char) 147); //WRITES "?" TO FILE (ASCII 63, NOT 147)
            fo.close();
        }catch(Exception e){
            return true;
        }
        return false;
    }

    public static boolean readFile(String path){
        try {
            BufferedReader fi = new BufferedReader(new FileReader(path));
            char c[] = fi.readLine().toCharArray();
            System.out.println((int) c[0]); //OBVIOUSLY PRINTS 63 INSTEAD OF 147
            fi.close();
            return true;
        } catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: barcode design in postgresql 
Java :: java writing an object 
Java :: sudo visudo quit without saving 
Java :: spigot self cancelling scheduler 
Java :: sort stream by key java 
Java :: detecting battery charging android 
Java :: speak function in java 
Java :: what is serialization in rest assured 
Java :: hint property of plain text in android studio 
Java :: how to get listview data, TextView 
Java :: function compose method java 8 
Java :: writing wehere clause in repository in springboot 
Java :: force orientation programmatically android 
Java :: telegraf-agent-configuration 
Java :: Clicking on Fragment goes through in Activity 
Java :: priority queue size jaa 
Java :: text with seek bar in android 
Java :: set skin minecraft entity player 
Java :: Java Copying Arrays Using arraycopy() method 
Java :: java spigot string to kyori textcomponent 
Java :: I/System.out: ep: android.os.NetworkOnMainThreadException 
Java :: scanner class in java 
Java :: java consonant regex 
Java :: ezra margolin 
Java :: at org.apache.spark.sql.errors.QueryCompilationErrors$.failedToFindKafkaDataSourceError(QueryCompilationErrors.scala:1037) 
Java :: 1 2 1 3 2 1 4 3 2 1 3 2 1 2 1 1 java 
Java :: bloomreach get node via id 
Java :: Example of ArrayDeque 
Java :: The larger and the smaller of the character “E” and the integer 71 java 
Java :: print different variable datatype 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =