Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,22 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadFile {
public static void main(String[] args) throws IOException{
String fileContents = readEntireFile("./foo.txt");
}
private static String readEntireFile(String filename) throws IOException {
FileReader in = new FileReader(filename);
StringBuilder contents = new StringBuilder();
char[] buffer = new char[4096];
int read = 0;
do {
contents.append(buffer, 0, read);
read = in.read(buffer);
} while (read >= 0);
in.close();
return contents.toString();
}
}

View file

@ -0,0 +1,20 @@
import java.nio.channels.FileChannel.MapMode;
import java.nio.MappedByteBuffer;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.File;
public class MMapReadFile {
public static void main(String[] args) throws IOException {
MappedByteBuffer buff = getBufferFor(new File(args[0]));
String results = new String(buff.asCharBuffer());
}
public static MappedByteBuffer getBufferFor(File f) throws IOException {
RandomAccessFile file = new RandomAccessFile(f, "r");
MappedByteBuffer buffer = file.getChannel().map(MapMode.READ_ONLY, 0, f.length());
file.close();
return buffer;
}
}

View file

@ -0,0 +1 @@
String content = new Scanner(new File("foo"), "UTF-8").useDelimiter("\\A").next();

View file

@ -0,0 +1,15 @@
import java.util.List;
import java.nio.charset.Charset;
import java.nio.file.*;
public class ReadAll {
public static List<String> readAllLines(String filesname){
Path file = Paths.get(filename);
return Files.readAllLines(file, Charset.defaultCharset());
}
public static byte[] readAllBytes(String filename){
Path file = Paths.get(filename);
return Files.readAllBytes(file);
}
}