用于Mac的Java文件输入 [英] File input in Java for Mac

查看:107
本文介绍了用于Mac的Java文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在学习编程类中的文件输入和输出,但是我有一台Macbook Pro。我知道如何做到这一点,我可以在Windows上做到这一点,但我很难找到如何正确地为Mac做到这一点。我似乎无法弄清楚在File Fred = new File()中引用什么内容。我需要在报价中加入什么才能起作用?我在名为David的HDD中有文件。

  import java.util.Scanner; 
import java.io. *;

public class FileIO
{

public static void main(String [] args)
{

File Fred =新文件(David:\\mytext.txt);
try


$ div class =h2_lin>解决方案Mac OS中,使用/(正斜杠)而不是\(反斜杠)来分隔路径中的文件。硬盘位于/卷下。所以你的文件可能是/Volumes/David/mytext.txt。


We're learning file input and output in my programming class right now, but I have a Macbook Pro. I understand how to do it and I can do it on Windows but I'm having trouble finding out how to do it exactly for a Mac. I just can't seem to figure out what to put in the quotes for the 'File Fred = new File(" "); What do I need to put in the quotes to have it work? I have the file in the HDD named "David".

import java.util.Scanner;
import java.io.*;

public class FileIO
{

public static void main(String[] args)
{

    File Fred = new File("David:\\mytext.txt");
    try
    {   

解决方案

On Mac OS, you use "/" (forward slash) and not "\" (backward slash) to separate files in a path. Hard drives are located under "/Volumes". So your file is probably /Volumes/David/mytext.txt .

这篇关于用于Mac的Java文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆