2017-12-04 1 views
-1

enter image description here방법이

그래서 내가, 내가 파일에 경로를 입력하고 그 후 나는 정보를 사용할 방법을 입력하는 첫 번째 파일 관리 작업이 필요 않는 프로그램을 만들 수있는 과제를 만들고 물건 그래서 f는 이미 사용하지만 어떻게이 문제를 해결하고 난 x와 프로그램 작품 F에서 변수를 변경하려하기 때문에 그것이 작동되도록하지만 그것의 경로에 파일을 찾을 수없는 말을하지

package file.manager; 

import java.io.File; 
import java.util.Scanner; 

public class FileManager { 
public static void main(String[] args) { 

    Scanner sc=new Scanner(System.in); 
    System.out.println("Unesi putanju"); 
    File f = new File(sc.nextLine()); 
    System.out.println("Unesi funkciju"); 
    switch(sc.next()) 

{ 
case "info": 
    File f = new File(sc.nextLine()); 
    if (f.exists()) 
     System.out.println(f.getName()+"exist!"); 
    else 
     System.out.println("this folder/file doesnt exist"); 
break; 

답변

1

코드가 이됩니다. 다른 들으면 표준 들여 쓰기를 따르십시오 :

Scanner sc=new Scanner(System.in); 
System.out.println("Unesi putanju"); 
File f = new File(sc.nextLine()); 
System.out.println("Unesi funkciju"); 
switch(sc.next()) 
{ 
    case "info": 
     File f = new File(sc.nextLine()); 
     if (f.exists()) 
      System.out.println(f.getName()+"exist!"); 
     else 
      System.out.println("this folder/file doesnt exist"); 
    break; 

다음 줄은 코드에 두 번 존재합니다. (case "info": 이후와 system.out.println 이후).

File f = new File(sc.nextLine()); 

두 개의 별도의 경로를 가지고 프로그램에서 두 개의 서로 다른 파일을 읽고 싶어하지 않는 한, 당신은 아마 두 번째를 제거해야합니다.