盘点lotnum批次号
parent
6e5c8fb47e
commit
1c15675ba6
@ -0,0 +1,59 @@
|
||||
package com.zhehekeji.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@Slf4j
|
||||
public class FileUtil {
|
||||
|
||||
public static void save(String text,String path){
|
||||
|
||||
//判断文件是否存在
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
fileOutputStream.write(text.getBytes());
|
||||
fileOutputStream.close();
|
||||
log.info("write text success :{}",text);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getText(String path){
|
||||
File file = new File(path);
|
||||
if(file.exists()){
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
byte[] bytes = new byte[1024];//定义字节长度
|
||||
int len = 0;
|
||||
String txt = null;
|
||||
while ((len = fileInputStream.read(bytes)) != -1) {//与文件读取出来的长度比较,内部有数据读完是-1,所以不等于-1
|
||||
txt = new String(bytes, 0, len);//从0取到有数据的末尾
|
||||
}
|
||||
|
||||
fileInputStream.close();
|
||||
return txt;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String path = "./lotnum_now";
|
||||
save("www",path);
|
||||
getText(path);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue