feat(代码生成模块): 添加测试代码
parent
c87236047c
commit
8b2412f428
@ -0,0 +1,17 @@
|
||||
package com.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BufferedInputFile {
|
||||
public static void main(String[] args) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("E:/data.txt"))) {
|
||||
System.out.println(reader.lines().collect(Collectors.joining("\n")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.test;
|
||||
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileRead {
|
||||
public static void main(String[] args) {
|
||||
try (FileReader fileReader = new FileReader("E:/data.txt")) {
|
||||
char arr[] = new char[1024];
|
||||
int len;
|
||||
while ((len = fileReader.read(arr)) != -1) {
|
||||
System.out.println(new String(arr,0 ,len));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class OSExecute {
|
||||
public static void command(String command) throws Exception {
|
||||
boolean err = false;
|
||||
try {
|
||||
Process process = new ProcessBuilder(
|
||||
command.split(" ")).start();
|
||||
try (
|
||||
BufferedReader results = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
process.getInputStream(), "gbK"));
|
||||
BufferedReader errors = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
process.getErrorStream()))
|
||||
) {
|
||||
results.lines()
|
||||
.forEach(System.out::println);
|
||||
err = errors.lines()
|
||||
.peek(System.err::println)
|
||||
.count() > 0;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (err)
|
||||
throw new Exception(
|
||||
"Errors executing " + command);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
command("java -version");
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.test;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestEOF {
|
||||
public static void main(String[] args) {
|
||||
try (DataInputStream in = new DataInputStream(new FileInputStream("E:/data.txt"))) {
|
||||
while (in.available() != 0) {
|
||||
System.out.write(in.readByte());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue