0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Jupyter学習ノート_002

Last updated at Posted at 2020-01-11

Google colabにJavaをコンパイルや実行する方法

下記の手順で実現できます。

  • Google colabへ接続して、Google driveにも接続する
test1.py
#google driveをマウントする
from google.colab import drive
drive.mount('/content/drive')
  • サンプルソース実行までの処理
test2.py
#カレントディレクトリを設定する
import os
import shutil
os.chdir('/content/drive/My Drive/Java_sample')
path_name = os.getcwd()

#ソースをアップロードして、指定フォルダーへコピーする
file_name = '/HelloWorld.java'
path_all = path_name + file_name
print(path_all)
shutil.copy(file_name, path_name)

#コマンドでJavaソースをコンパイル&実行する
!javac HelloWorld.java
!java HelloWorld
  • セルという仕組みでテストのため2つを分けています。(実施結果)
    実施結果
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?