質問編集履歴

1

実現したいことの具体例を追加。ソースコードの追加。

2017/09/20 14:13

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,10 @@
1
1
  ###前提・実現したいこと
2
2
 
3
3
  mainクラスから、ファイルの名前(ccc.txt)を指定して、相対パスを表示したいのですが、どんなファイル名(存在しないファイルだったとしても)を入力しても、必ず下記のメッセージ(ファイルの名前は入力した名前が表示されます)が表示されてしまいます。実際のccc.txtの場所は、C:\\filelist\\ccc.txtです。
4
+
5
+
6
+
7
+ 下記コードにて、ccc.txtと入力。ccc.txtの場所はC:\\filelist\\ccc.txtなので、アウトプットでC:\\filelist\\ccc.txtと表示させたいのですが、C:\Users\Work\Lab3\ccc.txtとなってしまいます。現在のディレクトリから見た、ccc.txtの場所の表示もさせたいです。
4
8
 
5
9
 
6
10
 
@@ -28,7 +32,35 @@
28
32
 
29
33
  ```java
30
34
 
35
+ package fileOp;
36
+
37
+ import java.io.*;
38
+
39
+
40
+
41
+ public class Main {
42
+
43
+ public static void main(String[] args) throws IOException {
44
+
45
+ ShowDir d = new ShowDir();
46
+
47
+
48
+
49
+ BufferedReader reader = new BufferedReader
50
+
51
+ (new InputStreamReader(System.in));
52
+
53
+ String path = reader.readLine();
54
+
55
+ d.path(path);
56
+
57
+ }
58
+
59
+
60
+
61
+ public class ShowDir {
62
+
31
- public void path(String filename) throws IOException {
63
+ public void path(String filename) throws IOException {
32
64
 
33
65
  File file = new File(filename);
34
66
 
@@ -52,6 +84,8 @@
52
84
 
53
85
  }
54
86
 
87
+ }
88
+
55
89
  ```
56
90
 
57
91