哎,何止一个错啊!!
import java.io.*;
class WriteToFile
{
public static void main(String args[]) throws IOException
{
System.out.println("Please enter a directory that the file located in:");
StringBuffer stfDir=new StringBuffer();
//while ((char ch = (char)System.in.read())!='\n')
char ch=(char)System.in.read();
while(ch!='\n') {
stfDir.append(ch);
ch=(char)System.in.read();
}
File dir=new File(stfDir.toString());
System.out.println("Please enter a filename that want to read:");
StringBuffer stfFilename=new StringBuffer();
//While ((char ch=(char)System.in.read())!='\n')
ch=(char)System.in.read();
while(ch!='\n')
{
stfFilename.append(ch);
ch=(char)System.in.read();
}
File readFrom=new File(dir,stfFilename.toString());
if (readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
{
//创建RandomAccessFile对象
RandomAccessFile rafFile=new RandomAccessFile(readFrom,"rw");
//如果未读到文件尾,则继续读取
int ch1=0;
StringBuffer stfContent=null;
while(ch1!=-1)
{
//字符缓冲区清空
stfContent.setLength(0);
//接收键盘输入,构造字符
while((ch1=System.in.read())!=-1)
stfContent.append(ch);
//附加Dos格式行结束标志
stfContent.append("\r\n");
//将字符缓冲区的内容写出
rafFile.writeBytes(stfContent.toString());
}
rafFile.close();
}
else
System.out.println("File cann't be write!");
}
}这样应该没有问题了
import java.io.*;
class WriteToFile
{
public static void main(String args[]) throws IOException
{
System.out.println("Please enter a directory that the file located in:");
StringBuffer stfDir=new StringBuffer();
//while ((char ch = (char)System.in.read())!='\n')
char ch=(char)System.in.read();
while(ch!='\n') {
stfDir.append(ch);
ch=(char)System.in.read();
}
File dir=new File(stfDir.toString());
System.out.println("Please enter a filename that want to read:");
StringBuffer stfFilename=new StringBuffer();
//While ((char ch=(char)System.in.read())!='\n')
ch=(char)System.in.read();
while(ch!='\n')
{
stfFilename.append(ch);
ch=(char)System.in.read();
}
File readFrom=new File(dir,stfFilename.toString());
if (readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
{
//创建RandomAccessFile对象
RandomAccessFile rafFile=new RandomAccessFile(readFrom,"rw");
//如果未读到文件尾,则继续读取
int ch1=0;
StringBuffer stfContent=null;
while(ch1!=-1)
{
//字符缓冲区清空
stfContent.setLength(0);
//接收键盘输入,构造字符
while((ch1=System.in.read())!=-1)
stfContent.append(ch);
//附加Dos格式行结束标志
stfContent.append("\r\n");
//将字符缓冲区的内容写出
rafFile.writeBytes(stfContent.toString());
}
rafFile.close();
}
else
System.out.println("File cann't be write!");
}
}这样应该没有问题了
解决方案 »
- 高手请进。。。。synchronized的使用迷惑。
- SSH项目开发诡异问题!
- hibernate映射问题
- 我们老师现在竟然在教我们struts1问起原因说是怕直接讲struts2大家不好理解。这是为何
- 这个最简单的webservice+ajax 应用怎么做啊?
- Spring如何注入配置文件
- 初学hibernate,看过一些文档,但是不知道写代码的流程,希望给点提示
- 公司技术员写的jar竟含源代码,怎末回事?
- 如何写一个通用的测试类?有好想法者给分,有实例另外加分!
- sevlet中超过1分钟,客户端无法收到响应数据
- 开发者上网推荐站点!!!
- 请问在jbuilder7,中jaxrpc.jar在哪儿?
import java.io.*;
class WriteToFile
{
public static void main(String args[]) throws IOException
{
System.out.println("Please enter a directory that the file located in:");
StringBuffer stfDir=new StringBuffer();
//while ((char ch = (char)System.in.read())!='\n')
char ch=(char)System.in.read();
while(ch!='\n') {
stfDir.append(ch);
ch=(char)System.in.read();
}
File dir=new File(stfDir.toString());
System.out.println("Please enter a filename that want to read:");
StringBuffer stfFilename=new StringBuffer();
//While ((char ch=(char)System.in.read())!='\n')
ch=(char)System.in.read();
while(ch!='\n')
{
stfFilename.append(ch);
ch=(char)System.in.read();
}
File readFrom=new File(dir,stfFilename.toString());
if (readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
{
//创建RandomAccessFile对象
RandomAccessFile rafFile=new RandomAccessFile(readFrom,"rw");
//如果未读到文件尾,则继续读取
int ch1=0;
StringBuffer stfContent=null;
while(ch1!=-1)
{
//字符缓冲区清空
stfContent.setLength(0);
//接收键盘输入,构造字符
while((ch1=System.in.read())!=-1)
stfContent.append(ch);
//附加Dos格式行结束标志
stfContent.append("\r\n");
//将字符缓冲区的内容写出
rafFile.writeBytes(stfContent.toString());
}
rafFile.close();
}
else
System.out.println("File cann't be write!");
}
}这样应该没有问题了