package io;import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class copy {

public static void main(String[] args) {
String filePath;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入信息:");
filePath = br.readLine();
File fileName = new File(filePath);
while(fileName.isDirectory()) {
System.out.println(fileName.getName() + "是一个目录请重新输入");
}
System.out.println(fileName.getName() + "是一个文件:");
try{
System.out.println("创建文件输入流对象……");
FileInputStream fis = FileInputStream(fileName.getName());//这行提示有错误
System.out.println("指定输入文件对象……");
byte data[] = new byte[100];
System.out.println("读入文件数组到指定数组中……");
fis.read(data);
String str = data.toString();
System.out.println("创建文件输出流对象……");
FileOutputStream fos = new FileOutputStream("copy.txt");
System.out.println("将指定数组的内容读入文件中……");
fos.write(str.getBytes());
System.out.println("关闭所有文件");
fis.close();
fos.close();
}
catch(Exception e){}
}}错误提示:Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method FileInputStream(String) is undefined for the type copy请问这个错误应该怎么改啊

解决方案 »

  1.   

    FileInputStream fis = FileInputStream(fileName.getName())
    直接这样:FileInputStream fis = FileInputStream(fileName)试试
      

  2.   

    你这一行怎么是FileInputStream fis = FileInputStream(fileName)
    应该要FileInputStream fis = new FileInputStream(fileName);这样调用吧。
      

  3.   

    FileInputStream fileInputStream = new FileInputStream(new File(path)); 
      

  4.   

    +1FileInputStream构造参数一般是一个文件比如FileInputStream(File file) 或者文件的路径FileInputStream(String name) 
    通过打开一个到实际文件的连接来创建一个 FileInputStream,该文件通过文件系统中的路径名 name 指定,没有通过文件名来构造的。多看看api吧
      

  5.   

    不加new表示FileInputStream是copy类的一个静态方法,返回类型是FileInputStream,这算什么呀,肯定是不对了的,加上new就对了,本来就是很简单的问题,看来楼主还菜的很呢。
      

  6.   

    FileInputStream fis = new FileInputStream(fileName.getName());//这行提示有错误
    fileName.getName()获取到的只是文件名,不包含路径的,到时候你会找不到文件的。直接传入fileName就可以了:FileInputStream fis = new FileInputStream(fileName);
      

  7.   

    改成FileInputStream fis = new FileInputStream(fileName);后运行,到了文件输入流对象就结束了,怎么回事?
    运行结果如下:
    请输入信息:射雕英雄传
    射雕英雄传是一个文件:
    创建文件输入流对象……
      

  8.   

    射雕英雄传 是一个文件吗? 这很明显不对  文件像 xxx.txt  
      

  9.   

    FileInputStream fis = FileInputStream(fileName.getName());//
    这个没有错
    难道java语法修改了