public class Resource {
public static void main(String[] args) {
writeFile("562");
readFileByChars();
}
public static void writeFile(String news_id) {
FileOutputStream fsOut = null;
String filePath = System.getProperty("user.dir")
+ "/conf/newsid.txt";
try {
fsOut = new FileOutputStream(filePath);
byte[] b1 = news_id.getBytes();
fsOut.write(b1);
fsOut.close();
System.out.println(news_id+"写入CT成功!");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fsOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String readFileByChars() {
String weixinid = "";
String filePath = System.getProperty("user.dir")
+ "/conf/newsid.txt";
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(filePath));
int tempchar;
while ((tempchar = reader.read()) != -1) {
if (((char) tempchar) != '
') {
// System.out.print((char) tempchar);
weixinid += (char) tempchar + "";
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return weixinid;
}
}