当前位置: 技术问答>java相关
错误的代码求答案.....
来源: 互联网 发布时间:2015-01-23
本文导语: 这条例子总是错误的,应该怎样改正? /********* Token.java*********/ import java.io.*; public class Token { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader( ...
这条例子总是错误的,应该怎样改正?
/********* Token.java*********/
import java.io.*;
public class Token
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(
new FileReader("linenum.txt"));
BufferedWriter bw=new BufferedWriter(
new FileWriter("token.txt"));
StreamTokenizer st=new StreamTokenizer(br);
int tokenType;
st.whitespaceChars(0,32);
st.eollsSignificant(true);
while(br.ready())
{
tokenType=st.nextToken();
switch(tokenType)
{
case st.TT_NUMBER:
bw.write(String.valueOf((long)st.nval));
bw.newLine();
break;
case st.TT_WORD:
bw.write(st.sval);
bw.newLine();
break;
default:
;
}
}
bw.close();
}
}
/********* Token.java*********/
import java.io.*;
public class Token
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(
new FileReader("linenum.txt"));
BufferedWriter bw=new BufferedWriter(
new FileWriter("token.txt"));
StreamTokenizer st=new StreamTokenizer(br);
int tokenType;
st.whitespaceChars(0,32);
st.eollsSignificant(true);
while(br.ready())
{
tokenType=st.nextToken();
switch(tokenType)
{
case st.TT_NUMBER:
bw.write(String.valueOf((long)st.nval));
bw.newLine();
break;
case st.TT_WORD:
bw.write(st.sval);
bw.newLine();
break;
default:
;
}
}
bw.close();
}
}
|
编译通过
import java.io.*;
public class Token
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(
new FileReader("linenum.txt"));
BufferedWriter bw=new BufferedWriter(
new FileWriter("token.txt"));
StreamTokenizer st=new StreamTokenizer(br);
int tokenType;
st.whitespaceChars(0,32);
st.eolIsSignificant(true) ;
while(br.ready())
{
tokenType=st.nextToken();
switch(tokenType)
{
case StreamTokenizer.TT_NUMBER:
bw.write(String.valueOf((long)st.nval));
bw.newLine();
break;
case StreamTokenizer.TT_WORD:
bw.write(st.sval);
bw.newLine();
break;
default:
;
}
}
bw.close();
}
}
import java.io.*;
public class Token
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(
new FileReader("linenum.txt"));
BufferedWriter bw=new BufferedWriter(
new FileWriter("token.txt"));
StreamTokenizer st=new StreamTokenizer(br);
int tokenType;
st.whitespaceChars(0,32);
st.eolIsSignificant(true) ;
while(br.ready())
{
tokenType=st.nextToken();
switch(tokenType)
{
case StreamTokenizer.TT_NUMBER:
bw.write(String.valueOf((long)st.nval));
bw.newLine();
break;
case StreamTokenizer.TT_WORD:
bw.write(st.sval);
bw.newLine();
break;
default:
;
}
}
bw.close();
}
}