这段代码应该在F盘生产一个txt.txt文件怎么没实现? public static void main(String[] argv) throws Exception { System.setOut(new PrintStream(new FileOutputStream(new File("D:" + File.separator + "txt.txt")))); System.out.println("今年的中秋节你过的快乐吗?"); } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我给你发个例子,你看看吧.//把session的值存储到记事本里面 try {// 获得tomcat的绝对路径 HttpSession session = request.getSession(); ServletContext application = session.getServletContext(); String serverRealPath = application.getRealPath("/") ; File file=new File(serverRealPath+"/loginLog.txt"); if(!file.exists()){ FileWriter fileWriter = new FileWriter(file,true); fileWriter.write("登录时间"+" "); fileWriter.write("用户名"+" "); fileWriter.write("\r\n"); fileWriter.flush(); fileWriter.close(); } FileWriter fileWriter = new FileWriter(file, true); fileWriter.write(Session.getSession("loginTime").toString()+" "); fileWriter.write(Session.getSession("userId").toString()); //fileWriter.write(Session.getSession("userName").toString()+" "); //fileWriter.write(Session.getSession("departmentName").toString()+" "); fileWriter.write("\r\n"); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); }及供参考. 告诉你,你的是什么为题,(new File("F:"+File.separator+"txt.txt"))这里面你用的是中文的 冒号 System.setOut(new PrintStream(new FileOutputStream(new File("F:/separatortxt.txt"))));这样的行得通的,要是你的不能生成txt文件,一可能是你路径有问题,二就是里面带有中文的符号,所以你把冒号啊括号啊什么的都检查一遍,绝对OK,我这边我试了下,冇得问题. import java.io.File;import java.io.FileOutputStream;import java.io.PrintStream;public class SystemOut1 { public static void main()throws Exception{ System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt")))); System.out.println("今年的中秋节你过的快乐吗?"); }} public static void main(String[] args) { try { System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt")))); } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println("今年的中秋节你过的快乐吗?"); System.out.println("asdadasdddddddddddsadasdasd"); }运行不压力 你这只是new了一个对象,没写任何东西,当然不会产生文件了 System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt")))); System.out.println("今年的中秋节你过的快乐吗?"); 没有报错,点击执行就没声了,f盘中也没生成txt.txt文件 亲测 负责下面代码到main函数运行try { System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt")))); System.out.println("今年的中秋节你过的快乐吗?"); } catch (FileNotFoundException e) { e.printStackTrace(); }问题在"F:" bat字符串替换问题 这两个接口,Comparable和Comparator有什么区别? 请教如何在java程序中搞定mysql5乱码? 求字符串函数!!!! 简单问题求助,如何得知Applet已经失去焦点,如IE最小化时 关于对awt的下拉列表框的键盘搜索操作 怎样保证JTextField中输入的是正数 jbuilder 故障,急啊!立马给分 请教一个Java初学者的问题! 又一个java初级问题,送分。 中文转二进制,在MD5,在base64 关于通过XMLBEANS读取XML文件时候的问题
//把session的值存储到记事本里面
try {
// 获得tomcat的绝对路径
HttpSession session = request.getSession();
ServletContext application = session.getServletContext();
String serverRealPath = application.getRealPath("/") ;
File file=new File(serverRealPath+"/loginLog.txt");
if(!file.exists()){
FileWriter fileWriter = new FileWriter(file,true);
fileWriter.write("登录时间"+" ");
fileWriter.write("用户名"+" ");
fileWriter.write("\r\n");
fileWriter.flush();
fileWriter.close();
}
FileWriter fileWriter = new FileWriter(file, true);
fileWriter.write(Session.getSession("loginTime").toString()+" ");
fileWriter.write(Session.getSession("userId").toString());
//fileWriter.write(Session.getSession("userName").toString()+" ");
//fileWriter.write(Session.getSession("departmentName").toString()+" ");
fileWriter.write("\r\n");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) { e.printStackTrace();
}
及供参考.
(new File("F:"+File.separator+"txt.txt"))
这里面你用的是中文的 冒号
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SystemOut1 {
public static void main()throws Exception{
System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
System.out.println("今年的中秋节你过的快乐吗?");
}
}
try {
System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("今年的中秋节你过的快乐吗?");
System.out.println("asdadasdddddddddddsadasdasd");
}运行不压力
System.out.println("今年的中秋节你过的快乐吗?");
System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
System.out.println("今年的中秋节你过的快乐吗?");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
问题在"F:"