package com.andy.yang;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class IOTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String path = "E:"+File.separator+"test.txt";
File file = new File(path);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (file.exists())
{
System.out.println("文件的路径为:" + file.getAbsolutePath() );
}
else
{
System.out.println("文件不存在");
}
Scanner input = new Scanner(System.in);
String str = input.nextLine();
FileOutputStream outFile = null;
try {
outFile = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
outFile.write(str.getBytes());
outFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Java IO操作
最新推荐文章于 2024-04-04 22:18:38 发布