java超难题,高手帮我看一下下哪里有错误,重谢!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java超难题,高手帮我看一下下哪里有错误,重谢!相关的知识,希望对你有一定的参考价值。

该程序要实现的是,读取一个文本文档,例如有1~10行,要求按10~1行的顺序输出.并保存予原文件.
/*
* Main.java
*
* Created on 2000年9月29日, 下午5:17
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication1;
import java.io.*;
import java.util.StringTokenizer;
/**
*
* @author admin
*/
public class Main

/** Creates a new instance of Main */
public Main()


/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
char[] buffer=new char[1024];
Reader reader =null;
try

reader=new FileReader("D:\\新建 文本文档.txt");

int offset;
while((offset=reader.read(buffer))>0)
System.out.print(new String(buffer,0,offset));

catch(FileNotFoundException e)

e.printStackTrace();

catch(IOException e)

e.printStackTrace();

finally

if(reader!=null)
try

reader.close();

catch( IOException e)

String s= new String(buffer);
String p=new String();
String m=new String();
StringTokenizer tokenizer=new StringTokenizer(s,"\n");
while(tokenizer.hasMoreTokens())

p=tokenizer.nextToken();
m=p+m+" ";


String q=new String();
StringTokenizer tokenizer1=new StringTokenizer(m,"");
while(tokenizer.hasMoreTokens())

q=tokenizer1.nextToken();
Writer writer=null;
try

writer=new FileWriter("D:\\新建 文本文档.txt");
writer.write(p);

catch (Exception e)

e.printStackTrace();

finally

if (writer!=null)
try

writer.close();

catch(IOException e)






你的程序没有错误,只是没有实现反转写入。

//package com.color.io;

/*
* Main.java
*
* Created on 2000年9月29日, 下午5:17
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

/**
*
* @author admin
*/
public class Main

/** Creates a new instance of Main */
public Main()


/**
* @param args
* the command line arguments
* @throws IOException
*/
public static void main(String[] args) throws IOException
// TODO code application logic here
//按文件大小来产生构建buffer
char[] buffer = new char[(int)new File("D:\\新建 文本文档.txt").length()];
Reader reader = null;
try
reader = new FileReader("D:\\新建 文本文档.txt");

int offset;
while ((offset = reader.read(buffer)) > 0)
System.out.print(new String(buffer, 0, offset));
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
finally
if (reader != null)
try
reader.close();
catch (IOException e)


//将整个文件读入,然后构造成一个String
String s = new String(buffer);
//将这个String按换行符拆分成String数组
String [] reverse = s.split("\r\n");
// 构造文件,原来那个文件
File file = new File("D:\\新建 文本文档.txt");
Writer writer = new FileWriter(file);
for(int i=reverse.length-1;i>=0;i--)
//反转写入
writer.write(reverse[i]+"\r\n");

writer.close();


参考技术A 哇哦 你搞错没有 你要我看到n年

但我有一个好办法 下载一个编程软件 将这些源程序代码粘贴进去

电运行 他会告诉你拿错了
参考技术B 你的思路有问题,给你一个思路:先把句子读到一个数组中就好办了, 参考技术C 哪错了,没看出来错啊!

JAVA程序的几个小问题,有空的大神帮我看下谢谢啦~也可以让我给你发程序帮忙调一下万分感谢3QQQQQQ

报错:
Description Resource Path Location Type
The operator + is undefined for the argument type(s) Integer, int LoginAction.java /MyOA/src/com/oa/struts/actions line 72 Java Problem

报错:The method setAccessTime(Integer) in the type AbstractUser is not applicable for the arguments (int)

报错:The method inttostr(int) in the type Change is not applicable for the arguments (Integer) UpfileAction.java

有可能是类型不匹配引起的. 最好把下面两个方法申明也贴出来看看.
setAccessTime(Integer) 参数必须是Integer, 不能是int; 必须先转换
Change.inttostr(int) 参数必须是int, 不能是Integer; 也必须先转换

转换方法:
//int到Integer:
Integer A=new Integer(int value);
或者Integer A=Integer.valueOf(a);

//Integer到int:
Integer A=new Integer(5);
int a=A.intValue();追问

谢谢你啦  只差这一个问题了

The operator + is undefined for the argument type(s) Integer, int LoginAction.java /MyOA/src/com/oa/struts/actions line 72 Java Problem

追答

把user.setAccessTime 定义的参数类型列出来看下.

追问

public void setAccessTime(java.lang.Integer accessTime)
this.accessTime = accessTime;

追答

user.setAccessTime(new Integer(user.getAccessTime().intValue()+1));

int和Integer是两种类型, 不能直接加减.

参考技术A 就是你写的那个方法不存在,你的应该是时间属性或者字符串吧?怎么可能直接加1呢
明显是错在这里,你想的太容易了追问

 

 

The operator + is undefined for the argument type(s) Integer, int LoginAction.java /MyOA/src/com/oa/struts/actions line 72 Java Problem

 

能帮我看看怎么改么、?谢啦

以上是关于java超难题,高手帮我看一下下哪里有错误,重谢!的主要内容,如果未能解决你的问题,请参考以下文章

请高手帮我看下SecureCRT里的这个错误是啥意思,本人小白。如下图、

请高手帮我看下线程的错误

大佬帮我看一下这道Python题我哪里错了

可以帮我看一下我这里是哪里错的,PHP连接MY SQL,需要设置啥吗

(非常急)求一牛人帮助解决一下POI导入excel表格的功能,搞定之后必有重谢。

求助高手帮我看一下utils为空或不是对象是怎么回事