Dateiproblem

  • Themenstarter Themenstarter gundu
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
G

gundu

Gast
Hi,

versuche ein Programm zu schreiben was Dateien kopiert:
Code:
import java.io.*;

public class copyFile
{

	public static void main( String[] args ) 
	{

		if( args.length != 2)
		{
			System.err.println("usage: java copyFile <src> <dest>");
			System.exit( 1 );
		}
		if( ( new File(args[0]).exists() ) == false ) {
			System.err.println("src existiert nicht !");
			System.exit( 1 );
		}
		try
		{
			FileInputStream input = new FileInputStream( args[0] );
			FileOutputStream output = new FileOutputStream( args[1] );
		}
		catch ( FileNotFoundException e )
		{
			e.printStackTrace();
		}

		byte[] buffer = new byte[ 0xFFFF ];

		try {
			for(int len; (len = input.read(buffer)) != -1;) 
			{
				output.write(buffer, 0, len);
			}
		}
		catch( IOException e )
		{
			e.printStackTrace();
		}
	}
}

Und erhalte aber folgenden Fehler:
Found 2 semantic errors compiling "copyFile.java":

31. for(int len; (len = input.read(buffer)) != -1😉
^---^
*** Semantic Error: No accessible field named "input" was found in type "copyFile".


33. output.write(buffer, 0, len);
^----^
*** Semantic Error: No accessible field named "output" was found in type "copyFile".

Und ich verstehe einfach ned wieso der da input und output nicht findet .. wurde doch etwas weiter drüber definiert 🙁

gundu
 
an der stelle gibts kein input/output mehr, die variablen sind nur im try block gültig, definier sie außerhalb vom try.

btw. welchen compiler benutzt du?
 
Hi,

hatte da auch schon versucht, indem ich direkt am funktionsanfang ein
FileInputStream input = null;
FileOutputStream output = null;

hatte, aber da kommt folgender Fehler:
Found 2 semantic errors compiling "copyFile.java":

23. output = new FileOutputStream( args[1] );
^--------------------------------------^
*** Semantic Error: The type of the right sub-expression, "java.io.FileOutputStream", is not assignable to the variable, of type "java.io.FileInputStream".


35. output.write(buffer, 0, len);
^--------------------------^
*** Semantic Error: No accessible method with signature "write(byte[], int, int)" was found in type "java.io.FileInputStream".

Compiler:
Code:
$ javac --version
Jikes Compiler - Version 1.22 - 3 October 2004
Copyright (C) IBM Corporation 1997-2003, 2004.
- Licensed Materials - Program Property of IBM - All Rights Reserved.
Originally written by Philippe Charles and David Shields of IBM Research,
Jikes is now maintained and refined by the Jikes Project at:
<http://ibm.com/developerworks/opensource/jikes>
Please consult this URL for more information and for reporting problems.
 
dann hast du wohl
FileOutputStream input = null;
FileInputStream output = null;
statt
FileInputStream input = null;
FileOutputStream output = null;
geschrieben ?
 
Sieht so aus als ob du FileInputStream output = null; irgendwo deklariert hättest, geht doch klar aus der Fehlermeldung hervor.
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben